capsula-capture-command 0.12.1

A Capsula hook that captures command execution output.
Documentation
use capsula_core::error::CapsulaError;
use thiserror::Error;

/// Command hook specific errors
#[derive(Debug, Error)]
pub enum CommandHookError {
    /// Command list is empty
    #[error("Command cannot be empty")]
    EmptyCommand,

    /// Command execution failed
    #[error("Failed to execute command '{command}': {source}")]
    ExecutionFailed {
        command: String,
        #[source]
        source: std::io::Error,
    },

    /// Command output contains invalid UTF-8
    #[error("Command output contains invalid UTF-8: {message}")]
    InvalidUtf8 { message: String },

    /// Command exited with non-zero status
    #[error("Command '{command}' exited with status {status}")]
    NonZeroExit { command: String, status: i32 },

    /// Serialization failed
    #[error("Failed to serialize command hook: {0}")]
    Serialization(#[from] serde_json::Error),
}

/// Convert `CommandHookError` to `CoreError`
impl From<CommandHookError> for CapsulaError {
    fn from(err: CommandHookError) -> Self {
        Self::HookFailed {
            hook: "capture-command".to_string(),
            source: Box::new(err),
        }
    }
}