crazy_train/
errors.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//! This module defines custom error types used in the Crazy Train library.
//!
//! The [`Error`] enum provides a comprehensive way to handle errors that may occur during the
//! execution of command steps and related operations.
//!
use crate::{executer::Output, step};

/// Represents errors that can occur in the Crazy Train library.
#[derive(thiserror::Error, Debug)]
pub enum Error {
    /// An error indicating that a specific step in the execution process has failed.
    #[error("Step failed: {:?}.\ndescription: {description}.\nstatus code: {:?}.\nstdout: {}.\nstderr: {}", kind, command_output.status_code, command_output.stdout, command_output.stderr)]
    StepError {
        kind: step::Kind,
        description: String,
        command_output: Output,
    },

    /// An error indicating a failure in input/output operations.
    #[error(transparent)]
    IO(#[from] std::io::Error),

    /// An error for UTF-8 conversion failures.
    #[error("UTF-8 conversion error: {0}")]
    Utf8(#[from] std::str::Utf8Error),

    /// A generic error type that captures any string error.
    #[error("{0}")]
    Any(String),
}

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