crazy_train/errors.rs
1//! This module defines custom error types used in the Crazy Train library.
2//!
3//! The [`Error`] enum provides a comprehensive way to handle errors that may occur during the
4//! execution of command steps and related operations.
5//!
6use crate::{executer::Output, step};
7
8/// Represents errors that can occur in the Crazy Train library.
9#[derive(thiserror::Error, Debug)]
10pub enum Error {
11 /// An error indicating that a specific step in the execution process has failed.
12 #[error("Step failed: {:?}.\ndescription: {description}.\nstatus code: {:?}.\nstdout: {}.\nstderr: {}", kind, command_output.status_code, command_output.stdout, command_output.stderr)]
13 StepError {
14 kind: step::Kind,
15 description: String,
16 command_output: Output,
17 },
18
19 /// An error indicating a failure in input/output operations.
20 #[error(transparent)]
21 IO(#[from] std::io::Error),
22
23 /// An error for UTF-8 conversion failures.
24 #[error("UTF-8 conversion error: {0}")]
25 Utf8(#[from] std::str::Utf8Error),
26
27 /// A generic error type that captures any string error.
28 #[error("{0}")]
29 Any(String),
30}
31
32pub type Result<T, E = Error> = std::result::Result<T, E>;