Skip to main content

harn_guard/
error.rs

1//! Error type for the guard package manager.
2
3use std::path::PathBuf;
4
5/// Failures from installing, resolving, or removing a guard model package.
6#[derive(Debug, thiserror::Error)]
7pub enum GuardError {
8    /// The requested catalog model name is not in the built-in catalog.
9    #[error("unknown guard model `{0}`; run `harn guard list` to see available models")]
10    UnknownModel(String),
11
12    /// A gated model was requested without an accepted license / credentials.
13    #[error(
14        "`{model}` is gated under {license}: accept the license at {license_url} and set HF_TOKEN, \
15         then re-run with --accept-license"
16    )]
17    Gated {
18        model: String,
19        license: String,
20        license_url: String,
21    },
22
23    /// Installation was attempted without accepting the model's license.
24    #[error(
25        "installing `{model}` requires accepting its license ({license} — {license_url}); \
26         pass --accept-license to confirm"
27    )]
28    LicenseNotAccepted {
29        model: String,
30        license: String,
31        license_url: String,
32    },
33
34    /// A downloaded file's SHA-256 did not match the catalog's pinned digest.
35    #[error("integrity check failed for `{file}`: expected {expected}, got {actual}")]
36    ChecksumMismatch {
37        file: String,
38        expected: String,
39        actual: String,
40    },
41
42    /// A required file was missing from the supplied install payload.
43    #[error("install payload is missing required file `{0}`")]
44    MissingFile(String),
45
46    /// The selector resolved to a filesystem path that does not exist.
47    #[error("guard model path does not exist: {0}")]
48    PathNotFound(PathBuf),
49
50    /// An on-disk manifest could not be parsed.
51    #[error("malformed guard manifest at {path}: {source}")]
52    Manifest {
53        path: PathBuf,
54        source: serde_json::Error,
55    },
56
57    /// Filesystem I/O error.
58    #[error("guard store I/O error at {path}: {source}")]
59    Io {
60        path: PathBuf,
61        source: std::io::Error,
62    },
63
64    /// The neural inference backend failed to load or run a model.
65    #[error("guard inference error: {0}")]
66    Inference(String),
67}
68
69/// Result alias for guard operations.
70pub type Result<T> = std::result::Result<T, GuardError>;