1#[derive(Debug)]
5#[non_exhaustive]
6pub enum CompilerError {
7 Symbol(docs_symbols::SymbolError),
10 Witness(docs_witness::WitnessError),
12 WitnessAssert(docs_witness::AssertionError),
14 Lean {
17 theorem: String,
19 detail: String,
21 },
22 Io {
25 path: String,
27 source: std::io::Error,
29 },
30 Render(docs_core::DocsError),
32 Attribute {
34 directive: &'static str,
36 reason: String,
38 },
39}
40
41impl std::fmt::Display for CompilerError {
42 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43 match self {
44 Self::Symbol(e) => write!(f, "include-symbol failed: {e}"),
45 Self::Witness(e) => write!(f, "witness failed: {e}"),
46 Self::WitnessAssert(e) => write!(f, "witness assertion failed: {e}"),
47 Self::Lean { theorem, detail } => {
48 write!(f, "lean-check failed for `{theorem}`: {detail}")
49 }
50 Self::Io { path, source } => write!(f, "cannot read `{path}`: {source}"),
51 Self::Attribute { directive, reason } => {
52 write!(f, "bad {directive} fence: {reason}")
53 }
54 Self::Render(e) => write!(f, "markdown render failed: {e}"),
55 }
56 }
57}
58
59impl std::error::Error for CompilerError {
60 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
61 match self {
62 Self::Symbol(e) => Some(e),
63 Self::Witness(e) => Some(e),
64 Self::WitnessAssert(e) => Some(e),
65 Self::Io { source, .. } => Some(source),
66 Self::Render(e) => Some(e),
67 _ => None,
68 }
69 }
70}