bare-script 0.1.1

The type-safe scripting authority for Rust. A framework for building robust shell commands and automation with 'Parse, don't validate' philosophy.
Documentation
//! Error types for script command operations.

use thiserror::Error;

/// Error type for script command operations.
#[derive(Error, Debug)]
pub enum ScriptError {
    /// Command not found.
    #[error("Command not found: {0}")]
    CommandNotFound(String),

    /// Permission denied.
    #[error("Permission denied: {0}")]
    PermissionDenied(String),

    /// Invalid argument.
    #[error("Invalid argument: {0}")]
    InvalidArgument(String),

    /// Invalid working directory.
    #[error("Invalid working directory: {0}")]
    InvalidWorkingDirectory(String),

    /// Command execution failed with exit code.
    #[error("Command failed with exit code {code}: {stderr}")]
    ExecutionFailed {
        /// Exit code returned by the command.
        code: i32,
        /// Standard error output from the command.
        stderr: String,
    },

    /// Command timed out.
    #[error("Command timed out after {0:?}")]
    Timeout(std::time::Duration),

    /// IO error.
    #[error("IO error: {0}")]
    IoError(#[from] std::io::Error),

    /// Environment error.
    #[error("Environment error: {0}")]
    EnvironmentError(String),

    /// Encoding error.
    #[error("Encoding error: {0}")]
    EncodingError(String),

    /// Validation error.
    #[error("Validation error: {0}")]
    ValidationError(String),

    /// Pipeline error.
    #[error("Pipeline error: {0}")]
    PipelineError(String),

    /// Pipeline is empty (no commands).
    #[error("Pipeline has no commands")]
    PipelineEmpty,

    /// Pipeline stdin connection error.
    #[error("Failed to connect pipeline stdin: {0}")]
    PipelineStdinError(String),

    /// Pipeline stdout connection error.
    #[error("Failed to connect pipeline stdout: {0}")]
    PipelineStdoutError(String),

    /// Argument validation error.
    #[error("Argument validation error: {0}")]
    ArgumentError(String),

    /// Child process error.
    #[error("Child process error: {0}")]
    ChildError(String),

    /// Shell execution error.
    #[error("Shell execution error: {0}")]
    ShellError(String),

    /// Generic error.
    #[error("Error: {0}")]
    Other(String),
}

/// Result type for script command operations.
pub type ScriptResult<T> = Result<T, ScriptError>;

impl From<std::process::Output> for ScriptError {
    fn from(output: std::process::Output) -> Self {
        let code = output.status.code().unwrap_or(-1);
        let stderr = String::from_utf8_lossy(&output.stderr).into_owned();
        ScriptError::ExecutionFailed { code, stderr }
    }
}