Skip to main content

docs_symbols/
error.rs

1//! Typed, exhaustive errors for symbol extraction.
2
3/// Everything that can go wrong resolving a symbol path.
4#[derive(Debug)]
5#[non_exhaustive]
6pub enum SymbolError {
7    /// The source does not parse cleanly (ERROR or MISSING nodes anywhere:
8    /// docs repositories compile, so a hostile or broken source must not
9    /// silently yield a wrong span).
10    Parse {
11        /// The first offending node kind and byte offset, for diagnosis.
12        reason: String,
13    },
14    /// The symbol path could not be resolved against the AST.
15    Unresolvable {
16        /// The full symbol path as given.
17        path: String,
18        /// The segment that failed and what was visible at that scope.
19        reason: String,
20    },
21    /// The symbol path is malformed (empty, or deeper than the resolver
22    /// descends).
23    BadPath {
24        /// Why the path was rejected.
25        reason: String,
26    },
27    /// The grammar failed to load (a build/packaging fault, not input).
28    Grammar(String),
29}
30
31impl std::fmt::Display for SymbolError {
32    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        match self {
34            Self::Parse { reason } => write!(f, "source does not parse cleanly: {reason}"),
35            Self::Unresolvable { path, reason } => {
36                write!(f, "symbol path `{path}` does not resolve: {reason}")
37            }
38            Self::BadPath { reason } => write!(f, "bad symbol path: {reason}"),
39            Self::Grammar(e) => write!(f, "grammar load failed: {e}"),
40        }
41    }
42}
43
44impl std::error::Error for SymbolError {}