mnem_ingest/error.rs
1//! Error type for the ingest pipeline.
2//!
3//! Kept intentionally small in Phase-B5a; additional variants (LLM failure,
4//! sidecar unavailable, embedder error) land in later sub-waves alongside
5//! the modules that raise them.
6
7use thiserror::Error;
8
9/// Errors produced by the ingest pipeline.
10#[derive(Debug, Error)]
11pub enum Error {
12 /// Parsing the source bytes failed.
13 ///
14 /// `what` names the parser (`"markdown"`, `"text"`) and `detail`
15 /// carries an upstream message suitable for logging - not for
16 /// end-user display.
17 #[error("ingest parse failed ({what}): {detail}")]
18 ParseFailed {
19 /// Short identifier of the parser that failed.
20 what: String,
21 /// Human-readable detail (may include upstream error text).
22 detail: String,
23 },
24
25 /// The supplied [`crate::SourceKind`] is not yet supported in this
26 /// sub-wave (e.g. PDF or Conversation before Phase-B5b/B5e).
27 #[error("ingest source unsupported: {what}")]
28 UnsupportedSource {
29 /// Which source / feature was requested.
30 what: String,
31 },
32
33 /// I/O failure reading a source artifact.
34 #[error("ingest I/O error: {0}")]
35 IoError(#[from] std::io::Error),
36
37 /// A downstream `Transaction::add_node` / `add_edge` returned an
38 /// error during pipeline execution. The embedded string carries the
39 /// upstream `mnem_core::Error` display text so we avoid a
40 /// cross-crate re-export while still preserving detail for logs.
41 #[error("ingest commit error: {0}")]
42 Commit(String),
43
44 /// An [`crate::extract::Extractor`] or embedder raised an error the
45 /// pipeline could not recover from.
46 #[error("ingest extractor error: {0}")]
47 Extractor(String),
48
49 /// An optional sidecar binary (docling / unstructured, feature-gated
50 /// in Phase-B5e) was requested but is not available on `PATH`, or
51 /// returned a non-zero exit status / malformed output.
52 ///
53 /// The `tool` field names the sidecar (`"docling"`,
54 /// `"unstructured-ingest"`); `detail` carries the failure mode
55 /// (`"binary not found"`, upstream stderr, or parse error).
56 #[error("ingest sidecar failure ({tool}): {detail}")]
57 Sidecar {
58 /// Short identifier of the sidecar that failed.
59 tool: String,
60 /// Human-readable detail (may include upstream stderr or parse
61 /// error text).
62 detail: String,
63 },
64
65 /// Catch-all for internal invariants. Prefer a typed variant for
66 /// anything a caller might branch on.
67 #[error("ingest error: {0}")]
68 Other(String),
69}
70
71impl Error {
72 /// Convert a `mnem_core::Error` into the wrapped [`Self::Commit`]
73 /// variant. Kept private to the module's consumers via this helper
74 /// so we do not have to publish a `From<mnem_core::Error>` impl
75 /// (which would force every downstream crate to depend on the same
76 /// mnem-core major version).
77 pub(crate) fn commit(err: impl std::fmt::Display) -> Self {
78 Self::Commit(err.to_string())
79 }
80}