agentsec-core 0.3.0

AgentSec core library — scan / web / paste logic, pure Rust
Documentation
//! Crate-wide error type.
//!
//! [`enum@Error`] is the only error type returned from public APIs in this crate.
//! Variants wrap common foreign errors (`std::io`, `serde_json`, `reqwest`,
//! `regex`) plus three string-tagged categories ([`Error::Config`],
//! [`Error::Scan`], [`Error::Sanitize`]) for domain failures that do not map
//! cleanly to a foreign error.
//!
//! No variant carries sensitive content (URLs / file paths may appear in the
//! `Display` form; raw HTTP bodies / pasted plaintext never do).

use thiserror::Error;

/// Top-level error for all `agentsec-core` operations.
///
/// Construct via `?` on a foreign error (auto-converted by [`From`]) or via
/// one of the string-tagged variants for domain-specific failures.
#[derive(Debug, Error)]
pub enum Error {
    #[error("io error: {0}")]
    Io(#[from] std::io::Error),

    #[error("json error: {0}")]
    Json(#[from] serde_json::Error),

    #[error("http error: {0}")]
    Http(#[from] reqwest::Error),

    #[error("regex error: {0}")]
    Regex(#[from] regex::Error),

    /// Configuration parse / load failure (currently unused; reserved for
    /// upcoming policy / config file loaders).
    #[error("config error: {0}")]
    Config(String),

    /// Scan-path or snapshot processing failure (e.g. snapshot JSON parse
    /// failed; see [`crate::scan::snapshot`]).
    #[error("scan error: {0}")]
    Scan(String),

    /// Sanitize / fetch failure (HTTP non-2xx, body cap exceeded, sanitize
    /// stage error). See [`crate::web::fetch`] for the body-cap / status rule.
    #[error("sanitize error: {0}")]
    Sanitize(String),

    /// Install / uninstall failure (file mutation, JSON patch, backup
    /// creation).
    #[error("installer: {0}")]
    Installer(String),
}

/// Convenience alias for `Result<T, agentsec_core::Error>`.
pub type Result<T> = std::result::Result<T, Error>;