claw-core 0.1.2

Embedded local database engine for ClawDB — an agent-native cognitive database
Documentation
//! Error types for claw-core.
//!
//! All public API errors are represented by [`ClawError`], a typed enum
//! backed by [`thiserror`]. Downstream crates should match on [`ClawError`]
//! variants rather than on the underlying error sources.

use thiserror::Error;

/// The unified error type for claw-core operations.
#[derive(Debug, Error)]
pub enum ClawError {
    /// An underlying SQLx database error occurred.
    #[error("database error: {0}")]
    Database(#[from] sqlx::Error),

    /// A migration step failed.
    #[error("migration error: {0}")]
    Migration(String),

    /// Configuration validation failed.
    #[error("configuration error: {0}")]
    Config(String),

    /// The requested record was not found.
    #[error("{entity} with id '{id}' not found")]
    NotFound {
        /// The entity type that was not found.
        entity: String,
        /// The identifier that was searched for.
        id: String,
    },

    /// A unique constraint violation occurred.
    #[error("{entity} with id '{id}' already exists")]
    Conflict {
        /// The entity type that already exists.
        entity: String,
        /// The conflicting identifier.
        id: String,
    },

    /// A serialization or deserialization error occurred.
    #[error("serialization error: {0}")]
    Serialization(#[from] serde_json::Error),

    /// A snapshot operation failed.
    #[error("snapshot error: {0}")]
    Snapshot(String),

    /// Snapshot checksum verification failed.
    #[error("snapshot corrupt: {0}")]
    SnapshotCorrupt(String),

    /// A transaction operation failed.
    #[error("transaction error: {0}")]
    Transaction(String),

    /// A cache operation failed.
    #[error("cache error: {0}")]
    Cache(String),

    /// The caller supplied invalid input.
    #[error("invalid input: {0}")]
    InvalidInput(String),

    /// An I/O error occurred (e.g. while managing snapshot files).
    #[error("I/O error: {0}")]
    IoError(#[from] std::io::Error),

    /// A store operation failed.
    #[error("store error: {0}")]
    Store(String),

    /// An index operation failed.
    #[error("index error: {0}")]
    Index(String),

    /// An unexpected internal error occurred.
    #[error("internal error: {0}")]
    Internal(String),
}

/// Convenience alias for `Result<T, ClawError>`.
pub type ClawResult<T> = Result<T, ClawError>;