Skip to main content

klasp_core/
error.rs

1//! `KlaspError` — typed error hierarchy for the core crate.
2//!
3//! Module boundaries inside `klasp-core` use these typed variants so callers
4//! can match on cause. The CLI layer (`klasp`) wraps with `anyhow` for
5//! ergonomic propagation; this is the "thiserror at boundaries, anyhow at
6//! the CLI" split called out in [docs/design.md §12].
7
8use std::path::PathBuf;
9
10use crate::protocol::GateError;
11use crate::source::CheckSourceError;
12use crate::surface::InstallError;
13
14pub type Result<T, E = KlaspError> = std::result::Result<T, E>;
15
16#[derive(Debug, thiserror::Error)]
17pub enum KlaspError {
18    #[error("io error at {path}: {source}")]
19    Io {
20        path: PathBuf,
21        #[source]
22        source: std::io::Error,
23    },
24
25    #[error("could not parse klasp.toml: {0}")]
26    ConfigParse(#[from] toml::de::Error),
27
28    #[error(
29        "klasp.toml declares version = {found}, but this build of klasp only \
30         understands version = {supported}. Upgrade klasp or downgrade the config."
31    )]
32    ConfigVersion { found: u32, supported: u32 },
33
34    #[error("klasp.toml not found in {searched:?}")]
35    ConfigNotFound { searched: Vec<PathBuf> },
36
37    #[error("gate protocol error: {0}")]
38    Protocol(#[from] GateError),
39
40    #[error("install error: {0}")]
41    Install(#[from] InstallError),
42
43    #[error("check source error: {0}")]
44    CheckSource(#[from] CheckSourceError),
45}