Skip to main content

docs_compiler/
error.rs

1//! Typed, exhaustive errors for the compile pipeline.
2
3/// Why a build failed. Every directive failure names its source.
4#[derive(Debug)]
5#[non_exhaustive]
6pub enum CompilerError {
7    /// An include-symbol fence failed (unknown file, unresolvable symbol,
8    /// parse error) — the inner error carries the details.
9    Symbol(docs_symbols::SymbolError),
10    /// A witness fence failed execution or its assertions did not hold.
11    Witness(docs_witness::WitnessError),
12    /// A witness fence's declared assertions did not match the run.
13    WitnessAssert(docs_witness::AssertionError),
14    /// A lean-check fence failed: the kernel rejected the file, or the
15    /// proof is not real (sorry), or the certificate went stale.
16    Lean {
17        /// The theorem named by the fence.
18        theorem: String,
19        /// What went wrong, for diagnosis.
20        detail: String,
21    },
22    /// A fenced directive named a file that does not exist or could not
23    /// be read.
24    Io {
25        /// The path as named in the fence (relative to the build root).
26        path: String,
27        /// The underlying error.
28        source: std::io::Error,
29    },
30    /// Markdown rendering failed after directive resolution.
31    Render(docs_core::DocsError),
32    /// A fence attribute was missing or malformed.
33    Attribute {
34        /// The directive kind.
35        directive: &'static str,
36        /// What was wrong.
37        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}