md_prune_image/
error.rs

1//! Custom error types for md-prune-image operations.
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6/// Main error type for md-prune-image operations.
7#[derive(Error, Debug)]
8pub enum Error {
9    /// Directory does not exist.
10    #[error("directory does not exist: {0}")]
11    DirectoryNotFound(PathBuf),
12
13    /// Path is not a directory.
14    #[error("path is not a directory: {0}")]
15    NotADirectory(PathBuf),
16
17    /// Failed to read file.
18    #[error("failed to read file: {path}")]
19    ReadFile {
20        path: PathBuf,
21        #[source]
22        source: std::io::Error,
23    },
24
25    /// Failed to delete file.
26    #[error("failed to delete file: {path}")]
27    DeleteFile {
28        path: PathBuf,
29        #[source]
30        source: std::io::Error,
31    },
32
33    /// Failed to move file.
34    #[error("failed to move file from {from} to {to}")]
35    MoveFile {
36        from: PathBuf,
37        to: PathBuf,
38        #[source]
39        source: std::io::Error,
40    },
41
42    /// Failed to create directory.
43    #[error("failed to create directory: {path}")]
44    CreateDirectory {
45        path: PathBuf,
46        #[source]
47        source: std::io::Error,
48    },
49
50    /// Failed to canonicalize path.
51    #[error("failed to canonicalize path: {path}")]
52    CanonicalizePath {
53        path: PathBuf,
54        #[source]
55        source: std::io::Error,
56    },
57
58    /// Failed to move to recycle bin.
59    #[error("failed to move to recycle bin: {path}")]
60    RecycleFile {
61        path: PathBuf,
62        #[source]
63        source: trash::Error,
64    },
65
66    /// Invalid regex pattern.
67    #[error("invalid regex pattern")]
68    InvalidRegex(#[from] regex::Error),
69}
70
71/// Convenience Result type alias.
72pub type Result<T> = std::result::Result<T, Error>;