openrunner 1.0.0

A Rust library for running OpenScript
Documentation
//! Error types for OpenRunner.

use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
    #[error("IO Error: {0}")]
    Io(#[from] std::io::Error),

    #[error("OpenScript not found in PATH or configured path")]
    OpenScriptNotFound,

    #[error("Command execution failed: {0}")]
    CommandFailed(String),

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

    #[error("Failed to capture stdout: {0}")]
    StdoutCapture(String),

    #[error("Failed to capture stderr: {0}")]
    StderrCapture(String),

    #[error("Invalid script file path")]
    InvalidPath,

    #[error("Could not create temporary file: {0}")]
    TempFile(String),
}

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

#[cfg(test)]
mod tests {
    use super::*;
    use std::time::Duration;

    #[test]
    fn test_error_display() {
        let io_err = Error::Io(std::io::Error::new(std::io::ErrorKind::Other, "test"));
        assert_eq!(io_err.to_string(), "IO Error: test");

        let timeout_err = Error::Timeout(Duration::from_secs(5));
        assert_eq!(timeout_err.to_string(), "Script timed out after 5s");
    }

    #[test]
    fn test_error_from() {
        let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
        let open_runner_err: Error = io_err.into();
        assert!(matches!(open_runner_err, Error::Io(_)));
    }
}