g8_core/error.rs
1//! Top-level error enum for `g8-core`.
2
3use crate::plan::PlanStatus;
4use thiserror::Error;
5
6/// Errors originating in `g8-core`.
7///
8/// Downstream crates define their own error types (e.g. `StoreError`,
9/// `ExtractorError`) and convert from `G8Error` via `#[from]`.
10///
11/// # Examples
12///
13/// ```
14/// use g8_core::G8Error;
15///
16/// let e = G8Error::InvalidId("empty string".into());
17/// assert!(e.to_string().contains("invalid ID"));
18/// ```
19#[derive(Debug, Error)]
20pub enum G8Error {
21 /// An ID string was invalid (empty or otherwise malformed).
22 #[error("invalid ID: {0}")]
23 InvalidId(String),
24
25 /// A magic-comment annotation could not be parsed.
26 #[error("invalid annotation: {0}")]
27 InvalidAnnotation(String),
28
29 /// A plan status transition is not permitted by the lifecycle graph.
30 #[error("invalid plan status transition: {from:?} -> {to:?}")]
31 InvalidStatusTransition { from: PlanStatus, to: PlanStatus },
32
33 /// A substrate name was referenced that has not been registered.
34 #[error("unknown substrate: {0}")]
35 UnknownSubstrate(String),
36
37 /// An I/O error propagated from a caller.
38 #[error("io: {0}")]
39 Io(#[from] std::io::Error),
40
41 /// A serde_json error propagated from a caller.
42 #[error("serde: {0}")]
43 Serde(#[from] serde_json::Error),
44}