aidoc_core/error.rs
1//! Error type for the aidoc pipeline.
2//!
3//! The pipeline is a two-stage sequence (index → generate) with an optional
4//! lint stage layered on top. Failures during generate carry an index-stage
5//! summary in the error itself so the caller can report both what succeeded
6//! and what failed without needing a side channel. This mirrors the facade
7//! error contract used by algocline's `hub_dist` (which this crate ports to
8//! rustdoc JSON).
9
10/// The result alias used throughout `aidoc-core`.
11pub type Result<T> = std::result::Result<T, Error>;
12
13/// All errors produced by the aidoc pipeline.
14#[derive(Debug, thiserror::Error)]
15pub enum Error {
16 /// `cargo metadata` failed while enumerating workspace crates.
17 #[error("cargo metadata failed: {0}")]
18 CargoMetadata(#[from] cargo_metadata::Error),
19
20 /// Invoking `cargo +nightly rustdoc` failed at the process level
21 /// (non-zero exit, missing toolchain, etc.).
22 #[error("cargo rustdoc failed: {message}")]
23 RustdocInvocation {
24 /// Human-readable description of the failure.
25 message: String,
26 },
27
28 /// Parsing the rustdoc JSON output failed.
29 #[error("rustdoc JSON parse failed: {0}")]
30 RustdocParse(#[from] serde_json::Error),
31
32 /// The rustdoc JSON output uses a `format_version` this crate does not
33 /// yet support. Bumping `rustdoc-types` is the typical fix.
34 #[error("rustdoc format version mismatch: expected {expected}, found {found}")]
35 FormatVersionMismatch {
36 /// The `format_version` this crate was built against.
37 expected: u32,
38 /// The `format_version` actually present in the JSON payload.
39 found: u32,
40 },
41
42 /// An I/O error while reading rustdoc JSON or writing output artifacts.
43 #[error("io: {0}")]
44 Io(#[from] std::io::Error),
45
46 /// Configuration parsing or validation failed (bad
47 /// `[package.metadata.aidoc]`, unknown projection, etc.).
48 #[error("config error: {message}")]
49 Config {
50 /// Human-readable description of the failure.
51 message: String,
52 },
53
54 /// The generate stage failed. Carries a compact index-stage summary so
55 /// callers can report both the successful indexing pass and the failure
56 /// site without an out-of-band channel.
57 #[error("generate stage failed: {source}\nindex summary: {index_summary}")]
58 Generate {
59 /// The underlying failure from the generate stage.
60 #[source]
61 source: Box<Error>,
62 /// Compact human-readable summary of the completed index stage.
63 index_summary: String,
64 },
65}