#[derive(Debug)]
#[non_exhaustive]
pub enum CompilerError {
Symbol(docs_symbols::SymbolError),
Witness(docs_witness::WitnessError),
WitnessAssert(docs_witness::AssertionError),
Lean {
theorem: String,
detail: String,
},
Io {
path: String,
source: std::io::Error,
},
Render(docs_core::DocsError),
Attribute {
directive: &'static str,
reason: String,
},
}
impl std::fmt::Display for CompilerError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Symbol(e) => write!(f, "include-symbol failed: {e}"),
Self::Witness(e) => write!(f, "witness failed: {e}"),
Self::WitnessAssert(e) => write!(f, "witness assertion failed: {e}"),
Self::Lean { theorem, detail } => {
write!(f, "lean-check failed for `{theorem}`: {detail}")
}
Self::Io { path, source } => write!(f, "cannot read `{path}`: {source}"),
Self::Attribute { directive, reason } => {
write!(f, "bad {directive} fence: {reason}")
}
Self::Render(e) => write!(f, "markdown render failed: {e}"),
}
}
}
impl std::error::Error for CompilerError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Symbol(e) => Some(e),
Self::Witness(e) => Some(e),
Self::WitnessAssert(e) => Some(e),
Self::Io { source, .. } => Some(source),
Self::Render(e) => Some(e),
_ => None,
}
}
}