Skip to main content

trash_cli_core/
errors.rs

1use std::{io, path::PathBuf};
2
3/// Shared error type used by all Rust command crates during migration.
4#[derive(thiserror::Error, Debug)]
5pub enum CoreError {
6    /// File system I/O failure.
7    #[error("I/O error while accessing {0}")]
8    Io(PathBuf, #[source] io::Error),
9
10    /// A path is invalid for the current operation.
11    #[error("invalid path: {0}")]
12    InvalidPath(String),
13
14    /// A required input is missing.
15    #[error("missing required value: {0}")]
16    MissingValue(String),
17
18    /// An operation was rejected due to configuration/argument issues.
19    #[error("invalid command input: {0}")]
20    InvalidInput(String),
21
22    /// The operation could not be completed because a pre-condition failed.
23    #[error("pre-condition failed: {0}")]
24    PreconditionFailed(String),
25
26    /// A conflict prevented the operation from proceeding.
27    #[error("resource conflict: {0}")]
28    Conflict(String),
29
30    /// Platform-specific behavior not available in this environment.
31    #[error("unsupported platform behavior: {0}")]
32    UnsupportedPlatform(String),
33}
34
35impl CoreError {
36    pub fn invalid_input(message: impl Into<String>) -> Self {
37        Self::InvalidInput(message.into())
38    }
39
40    pub fn missing(message: impl Into<String>) -> Self {
41        Self::MissingValue(message.into())
42    }
43
44    pub fn conflict(message: impl Into<String>) -> Self {
45        Self::Conflict(message.into())
46    }
47
48    pub fn io(path: impl Into<PathBuf>, error: io::Error) -> Self {
49        Self::Io(path.into(), error)
50    }
51}
52
53/// Shared result alias for the core crate.
54pub type Result<T> = std::result::Result<T, CoreError>;