Skip to main content

starbase_utils/
fs_error.rs

1#![allow(unused_assignments)]
2
3use starbase_styles::{Style, Stylize};
4use std::path::PathBuf;
5use thiserror::Error;
6
7///.File system errors.
8#[cfg(not(feature = "miette"))]
9#[derive(Error, Debug)]
10pub enum FsError {
11    #[error("Failed to copy {} to {}.\n{error}", .from.style(Style::Path), .to.style(Style::Path))]
12    Copy {
13        from: PathBuf,
14        to: PathBuf,
15        #[source]
16        error: Box<std::io::Error>,
17    },
18
19    #[error("Failed to create {}.\n{error}", .path.style(Style::Path))]
20    Create {
21        path: PathBuf,
22        #[source]
23        error: Box<std::io::Error>,
24    },
25
26    #[error("Failed to lock {}.\n{error}", .path.style(Style::Path))]
27    Lock {
28        path: PathBuf,
29        #[source]
30        error: Box<std::io::Error>,
31    },
32
33    #[error("Failed to update permissions for {}.\n{error}", .path.style(Style::Path))]
34    Perms {
35        path: PathBuf,
36        #[source]
37        error: Box<std::io::Error>,
38    },
39
40    #[error("Failed to read path {}.\n{error}", .path.style(Style::Path))]
41    Read {
42        path: PathBuf,
43        #[source]
44        error: Box<std::io::Error>,
45    },
46
47    #[error("Failed to remove path {}.\n{error}", .path.style(Style::Path))]
48    Remove {
49        path: PathBuf,
50        #[source]
51        error: Box<std::io::Error>,
52    },
53
54    #[error("A directory is required for path {}.", .path.style(Style::Path))]
55    RequireDir { path: PathBuf },
56
57    #[error("A file is required for path {}.", .path.style(Style::Path))]
58    RequireFile { path: PathBuf },
59
60    #[error("Failed to rename {} to {}.\n{error}", .from.style(Style::Path), .to.style(Style::Path))]
61    Rename {
62        from: PathBuf,
63        to: PathBuf,
64        #[source]
65        error: Box<std::io::Error>,
66    },
67
68    #[error("Failed to unlock {}.\n{error}", .path.style(Style::Path))]
69    Unlock {
70        path: PathBuf,
71        #[source]
72        error: Box<std::io::Error>,
73    },
74
75    #[error("Failed to write {}.\n{error}", .path.style(Style::Path))]
76    Write {
77        path: PathBuf,
78        #[source]
79        error: Box<std::io::Error>,
80    },
81}
82
83///.File system errors.
84#[cfg(feature = "miette")]
85#[derive(Error, Debug, miette::Diagnostic)]
86pub enum FsError {
87    #[diagnostic(code(fs::copy), help("Does the source file exist?"))]
88    #[error("Failed to copy {} to {}.", .from.style(Style::Path), .to.style(Style::Path))]
89    Copy {
90        from: PathBuf,
91        to: PathBuf,
92        #[source]
93        error: Box<std::io::Error>,
94    },
95
96    #[diagnostic(code(fs::create))]
97    #[error("Failed to create {}.", .path.style(Style::Path))]
98    Create {
99        path: PathBuf,
100        #[source]
101        error: Box<std::io::Error>,
102    },
103
104    #[diagnostic(code(fs::lock))]
105    #[error("Failed to lock {}.", .path.style(Style::Path))]
106    Lock {
107        path: PathBuf,
108        #[source]
109        error: Box<std::io::Error>,
110    },
111
112    #[diagnostic(code(fs::perms))]
113    #[error("Failed to update permissions for {}.", .path.style(Style::Path))]
114    Perms {
115        path: PathBuf,
116        #[source]
117        error: Box<std::io::Error>,
118    },
119
120    #[diagnostic(code(fs::read))]
121    #[error("Failed to read path {}.", .path.style(Style::Path))]
122    Read {
123        path: PathBuf,
124        #[source]
125        error: Box<std::io::Error>,
126    },
127
128    #[diagnostic(code(fs::remove))]
129    #[error("Failed to remove path {}.", .path.style(Style::Path))]
130    Remove {
131        path: PathBuf,
132        #[source]
133        error: Box<std::io::Error>,
134    },
135
136    #[diagnostic(code(fs::require_dir))]
137    #[error("A directory is required for path {}.", .path.style(Style::Path))]
138    RequireDir { path: PathBuf },
139
140    #[diagnostic(code(fs::require_file))]
141    #[error("A file is required for path {}.", .path.style(Style::Path))]
142    RequireFile { path: PathBuf },
143
144    #[diagnostic(code(fs::rename), help("Does the source file exist?"))]
145    #[error("Failed to rename {} to {}.", .from.style(Style::Path), .to.style(Style::Path))]
146    Rename {
147        from: PathBuf,
148        to: PathBuf,
149        #[source]
150        error: Box<std::io::Error>,
151    },
152
153    #[diagnostic(code(fs::unlock))]
154    #[error("Failed to unlock {}.", .path.style(Style::Path))]
155    Unlock {
156        path: PathBuf,
157        #[source]
158        error: Box<std::io::Error>,
159    },
160
161    #[diagnostic(code(fs::write), help("Does the parent directory exist?"))]
162    #[error("Failed to write {}.", .path.style(Style::Path))]
163    Write {
164        path: PathBuf,
165        #[source]
166        error: Box<std::io::Error>,
167    },
168}