agentsec_core/error.rs
1//! Crate-wide error type.
2//!
3//! [`enum@Error`] is the only error type returned from public APIs in this crate.
4//! Variants wrap common foreign errors (`std::io`, `serde_json`, `reqwest`,
5//! `regex`) plus three string-tagged categories ([`Error::Config`],
6//! [`Error::Scan`], [`Error::Sanitize`]) for domain failures that do not map
7//! cleanly to a foreign error.
8//!
9//! No variant carries sensitive content (URLs / file paths may appear in the
10//! `Display` form; raw HTTP bodies / pasted plaintext never do).
11
12use thiserror::Error;
13
14/// Top-level error for all `agentsec-core` operations.
15///
16/// Construct via `?` on a foreign error (auto-converted by [`From`]) or via
17/// one of the string-tagged variants for domain-specific failures.
18#[derive(Debug, Error)]
19pub enum Error {
20 #[error("io error: {0}")]
21 Io(#[from] std::io::Error),
22
23 #[error("json error: {0}")]
24 Json(#[from] serde_json::Error),
25
26 #[error("http error: {0}")]
27 Http(#[from] reqwest::Error),
28
29 #[error("regex error: {0}")]
30 Regex(#[from] regex::Error),
31
32 /// Configuration parse / load failure (currently unused; reserved for
33 /// upcoming policy / config file loaders).
34 #[error("config error: {0}")]
35 Config(String),
36
37 /// Scan-path or snapshot processing failure (e.g. snapshot JSON parse
38 /// failed; see [`crate::scan::snapshot`]).
39 #[error("scan error: {0}")]
40 Scan(String),
41
42 /// Sanitize / fetch failure (HTTP non-2xx, body cap exceeded, sanitize
43 /// stage error). See [`crate::web::fetch`] for the body-cap / status rule.
44 #[error("sanitize error: {0}")]
45 Sanitize(String),
46
47 /// Install / uninstall failure (file mutation, JSON patch, backup
48 /// creation).
49 #[error("installer: {0}")]
50 Installer(String),
51}
52
53/// Convenience alias for `Result<T, agentsec_core::Error>`.
54pub type Result<T> = std::result::Result<T, Error>;