Skip to main content

lightshuttle_spec/
error.rs

1//! Error type returned while resolving a manifest resource into a
2//! container specification.
3
4/// Shorthand alias for `std::result::Result<T, SpecError>`.
5///
6/// All fallible operations in this crate return this type.
7///
8/// # Example
9///
10/// ```rust
11/// use lightshuttle_spec::{Result, SpecError};
12///
13/// fn check(ok: bool) -> Result<u32> {
14///     if ok {
15///         Ok(42)
16///     } else {
17///         Err(SpecError::InvalidSpec("something went wrong".into()))
18///     }
19/// }
20///
21/// assert!(check(true).is_ok());
22/// assert!(check(false).is_err());
23/// ```
24pub type Result<T> = std::result::Result<T, SpecError>;
25
26/// Errors raised while building a [`crate::ContainerSpec`] from a
27/// manifest resource declaration.
28///
29/// All variants carry a human-readable description of what is invalid
30/// so callers can surface a clear diagnostic to the user.
31///
32/// # Example
33///
34/// ```rust
35/// use lightshuttle_spec::SpecError;
36///
37/// let err = SpecError::InvalidSpec("port 99999 out of range".into());
38/// assert!(err.to_string().contains("invalid container spec"));
39/// ```
40#[derive(Debug, thiserror::Error)]
41pub enum SpecError {
42    /// The resolved specification is structurally invalid (bad port,
43    /// volume, duration, or healthcheck declaration).
44    ///
45    /// The inner `String` contains a description of the specific field
46    /// that failed validation.
47    #[error("invalid container spec: {0}")]
48    InvalidSpec(String),
49}