Skip to main content

shadow_core/
error.rs

1//! Error types for `shadow-core`.
2//!
3//! Every module defines its own typed error and flattens it into this
4//! top-level enum via `#[from]`. User-facing messages end with a `hint:` line
5//! so callers know what to do next.
6
7use thiserror::Error;
8
9/// The top-level error type returned by `shadow-core`.
10#[derive(Debug, Error)]
11#[non_exhaustive]
12pub enum Error {
13    /// Wrapped `std::io::Error` from filesystem or network operations.
14    #[error("io error: {0}\nhint: check file permissions and disk space")]
15    Io(#[from] std::io::Error),
16
17    /// JSON parse or serialization error (see SPEC §3 for the envelope schema).
18    #[error(
19        "json error: {0}\nhint: verify the record matches the .agentlog envelope from SPEC §3"
20    )]
21    Json(#[from] serde_json::Error),
22
23    /// SQLite error from the index store.
24    #[error("sqlite error: {0}\nhint: the .shadow/index.sqlite file may be corrupt; delete and re-index")]
25    Sqlite(#[from] rusqlite::Error),
26
27    /// Catch-all for domain errors that don't yet have a dedicated variant.
28    /// Prefer adding a typed variant for new error classes; `Other` is for
29    /// one-off messages that won't be matched on by callers.
30    #[error("{0}")]
31    Other(String),
32}