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