opys-engine 0.12.0

Core library for opys — a file-based inventory of typed markdown documents with a verify gate and SQL query layer
Documentation
use std::path::PathBuf;

/// Errors raised by library operations.
///
/// Content problems found by `verify` are *not* errors — they are collected
/// into a list and reported with a dedicated exit code. These variants cover
/// usage mistakes and runtime/IO failures.
#[derive(Debug, thiserror::Error)]
pub enum OpysError {
    #[error("{0} not found — run 'opys init' first")]
    ConfigNotFound(PathBuf),

    #[error("{id} not found")]
    NotFound { id: String },

    /// A usage mistake (bad flags, failed guard, etc.). Mirrors the Python
    /// tool's `sys.exit("error: …")` cases.
    #[error("{0}")]
    Usage(String),

    /// A failure inside the in-memory SQL store (a malformed internal
    /// statement, an impossible decode). Always a bug, never user error —
    /// the message is prefixed so tests can never accidentally match it.
    #[error("internal store error: {0}")]
    Store(String),

    #[error("{path}: {source}")]
    Toml {
        path: PathBuf,
        #[source]
        source: toml::de::Error,
    },

    #[error(transparent)]
    Io(#[from] std::io::Error),
}

/// Convenience for raising a usage error.
pub fn usage(msg: impl Into<String>) -> OpysError {
    OpysError::Usage(msg.into())
}

pub type Result<T> = std::result::Result<T, OpysError>;