workspacer_interface/
errors.rs

1// ---------------- [ File: src/errors.rs ]
2crate::ix!();
3
4error_tree!{
5
6    #[derive(Clone)]
7    pub enum CargoTomlWriteError {
8        WriteWorkspaceHeaderError {
9            io: Arc<io::Error>,
10        },
11        OpenWorkspaceMembersFieldError {
12            io: Arc<io::Error>,
13        },
14        WritePackageSectionError {
15            io: Arc<io::Error>,
16        },
17        WriteWorkspaceMember {
18            io: Arc<io::Error>,
19        },
20        CloseWorkspaceMembersFieldError {
21            io: Arc<io::Error>,
22        },
23        WriteError {
24            io: Arc<io::Error>,
25            cargo_toml_file: PathBuf,
26        },
27    }
28
29    #[derive(Clone)]
30    pub enum CargoTomlError {
31        ReadError {
32            io: Arc<io::Error>,
33        },
34        CargoTomlWriteError(CargoTomlWriteError),
35        MissingRequiredFieldForPublishing {
36            cargo_toml_file: PathBuf,
37            field: String,
38        },
39        MissingRequiredFieldForIntegrity {
40            cargo_toml_file: PathBuf,
41            field: String,
42        },
43        InvalidVersionFormat {
44            cargo_toml_file: PathBuf,
45            version: String,
46        },
47        MissingPackageSection {
48            cargo_toml_file: PathBuf,
49        },
50        TomlParseError {
51            cargo_toml_file: PathBuf,
52            toml_parse_error: toml::de::Error,
53        },
54        TomlEditError {
55            cargo_toml_file: PathBuf,
56            toml_parse_error: toml_edit::TomlError,
57        },
58        
59        // Error indicating that a file was not found.
60        FileNotFound {
61            missing_file: PathBuf,
62        },
63
64        FileIsNotAFile {
65            invalid_path: PathBuf,
66        },
67    }
68
69    #[derive(Clone)]
70    pub enum TestFailure {
71        UnknownError {
72            stdout: Option<String>,
73            stderr: Option<String>,
74        }
75    }
76
77    #[derive(Clone)]
78    pub enum TokioError {
79        JoinError {
80            join_error: Arc<tokio::task::JoinError>,
81        },
82    }
83
84    #[derive(Clone)]
85    pub enum DirectoryError {
86        CreateDirAllError {
87            io: Arc<io::Error>,
88        },
89        ReadDirError {
90            io: Arc<io::Error>,
91        },
92        GetNextEntryError {
93            io: Arc<io::Error>,
94        },
95    }
96
97    #[derive(Clone)]
98    pub enum ReadmeWriteError {
99        WriteBlankReadmeError {
100            io: Arc<io::Error>,
101        },
102    }
103
104    #[derive(Clone)]
105    pub enum CrateWriteError {
106        ReadmeWriteError(ReadmeWriteError),
107        WriteDummyMainError {
108            io: Arc<io::Error>,
109        },
110        WriteDummyTestError {
111            io: Arc<io::Error>,
112        },
113        WriteLibRsFileError {
114            io: Arc<io::Error>,
115        },
116        WriteMainFnError {
117            io: Arc<io::Error>,
118        },
119    }
120
121    #[derive(Clone)]
122    pub enum TestCoverageError {
123        TestFailure {
124            stdout: Option<String>,
125            stderr: Option<String>,
126        },
127        UnknownError {
128            stdout: Option<String>,
129            stderr: Option<String>,
130        },
131        CoverageParseError,
132        CommandError {
133            io: Arc<io::Error>,
134        },
135    }
136
137    #[derive(Clone)]
138    pub enum CargoDocError {
139        CommandError {
140            io: Arc<io::Error>,
141        },
142        UnknownError {
143            stdout: Option<String>,
144            stderr: Option<String>,
145        }
146    }
147
148    #[derive(Clone)]
149    pub enum LintingError {
150        CommandError {
151            io: Arc<io::Error>,
152        },
153        UnknownError {
154            stdout: Option<String>,
155            stderr: Option<String>,
156        }
157    }
158
159    #[derive(Clone)]
160    pub enum CargoMetadataError {
161        MetadataError {
162            error: Arc<cargo_metadata::Error>,
163        },
164        CircularDependency,
165        CyclicPackageDependency,
166    }
167
168    #[derive(Clone)]
169    pub enum BuildError {
170        CommandError {
171            io: Arc<io::Error>,
172        },
173        BuildFailed {
174            stderr: String,
175        },
176    }
177}
178
179error_tree!{
180
181    #[derive(Clone)]
182    pub enum CrateError {
183        LockfileParseFailed {
184            path:    PathBuf,
185            message: String,
186        },
187        // Error indicating that a file was not found.
188        FileNotFound {
189            missing_file: PathBuf,
190        },
191
192        // Error indicating that a directory was not found.
193        DirectoryNotFound {
194            missing_directory: PathBuf,
195        },
196
197        FailedToGetFileNameForPath {
198            path: PathBuf,
199        },
200
201        DirectoryError(DirectoryError),
202        CargoTomlError(CargoTomlError),
203
204        IoError {
205            io_error: Arc<io::Error>,
206            context: String,
207        },
208    }
209}
210
211error_tree!{
212
213    #[derive(Clone)]
214    pub enum WatchError {
215        NotifyError(Arc<notify::Error>),
216        IoError {
217            io:      Arc<io::Error>,
218            context: String,
219        },
220        ChannelRecvError(std::sync::mpsc::RecvError),
221    }
222
223    #[derive(Clone)]
224    pub enum GitError {
225        FailedToRunGitStatusMakeSureGitIsInstalled,
226        WorkingDirectoryIsNotCleanAborting,
227        IoError {
228            io:      Arc<io::Error>,
229            context: String,
230        }
231    }
232
233    // Enum representing possible errors in the `workspace-detail` crate.
234    #[derive(Clone)]
235    pub enum WorkspaceError {
236        ActuallyInSingleCrate {
237            path: PathBuf,
238        },
239        GitError(GitError),
240        CrateError(CrateError),
241        CratePinFailed {
242            crate_path: PathBuf,
243            source:     Box<CrateError>,
244        },
245
246        TokioJoinError {
247            join_error: Arc<tokio::task::JoinError>,
248        },
249        IoError {
250            io_error: Arc<io::Error>,
251            context:  String,
252        },
253        InvalidLockfile {
254            path:    PathBuf,
255            message: String,
256        },
257
258        // Error indicating that a file was not found.
259        FileNotFound {
260            missing_file: PathBuf,
261        },
262
263        InvalidWorkspace {
264            invalid_workspace_path: PathBuf,
265        },
266
267        CargoDocError(CargoDocError),
268        CrateWriteError(CrateWriteError),
269        ReadmeWriteError(ReadmeWriteError),
270        TokioError(TokioError),
271        CargoMetadataError(CargoMetadataError),
272        CircularDependency {
273            // To store the detected cycles
274            detected_cycles: Vec<Vec<String>>,
275        },  
276        CoverageParseError,
277        DirectoryRemovalError,
278        FileRemovalError,
279        InvalidCargoToml(CargoTomlError),
280        CargoTomlWriteError(CargoTomlWriteError),
281        LintingError(LintingError),
282        MultipleErrors(Vec<WorkspaceError>),
283        TestCoverageError(TestCoverageError),
284        TestFailure(TestFailure),
285        WatchError(WatchError),
286        BuildError(BuildError),
287        FileError(FileError),
288        DirectoryError(DirectoryError),
289        WorkspaceNotReadyForCargoPublish,
290        FileWatchError,
291        TestTimeout,
292    }
293}
294
295impl From<tokio::task::JoinError> for WorkspaceError {
296    fn from(join_error: tokio::task::JoinError) -> Self {
297        WorkspaceError::TokioJoinError {
298            join_error: Arc::new(join_error),
299        }
300    }
301}
302
303impl From<io::Error> for WorkspaceError {
304    fn from(io_error: io::Error) -> Self {
305        WorkspaceError::IoError {
306            io_error: Arc::new(io_error),
307            context: "no explicit context".to_string()
308        }
309    }
310}
311
312impl fmt::Display for WorkspaceError {
313    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
314        write!(f, "{:#?}", self)
315    }
316}
317
318impl CargoMetadataError {
319
320    pub fn is_cyclic_package_dependency_error(&self) -> bool {
321        self.to_string().contains("cyclic package dependency")
322    }
323}
324
325impl fmt::Display for CargoMetadataError {
326    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
327        write!(f, "{:#?}", self)
328    }
329}