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        SemverError(Arc<semver::Error>),
68    }
69
70    #[derive(Clone)]
71    pub enum TestFailure {
72        UnknownError {
73            stdout: Option<String>,
74            stderr: Option<String>,
75        }
76    }
77
78    #[derive(Clone)]
79    pub enum TokioError {
80        JoinError {
81            join_error: Arc<tokio::task::JoinError>,
82        },
83    }
84
85    #[derive(Clone)]
86    pub enum DirectoryError {
87        CreateDirAllError {
88            io: Arc<io::Error>,
89        },
90        ReadDirError {
91            io: Arc<io::Error>,
92        },
93        GetNextEntryError {
94            io: Arc<io::Error>,
95        },
96    }
97
98    #[derive(Clone)]
99    pub enum ReadmeWriteError {
100        WriteBlankReadmeError {
101            io: Arc<io::Error>,
102        },
103    }
104
105    #[derive(Clone)]
106    pub enum CrateWriteError {
107        ReadmeWriteError(ReadmeWriteError),
108        WriteDummyMainError {
109            io: Arc<io::Error>,
110        },
111        WriteDummyTestError {
112            io: Arc<io::Error>,
113        },
114        WriteLibRsFileError {
115            io: Arc<io::Error>,
116        },
117        WriteMainFnError {
118            io: Arc<io::Error>,
119        },
120    }
121
122    #[derive(Clone)]
123    pub enum TestCoverageError {
124        TestFailure {
125            stdout: Option<String>,
126            stderr: Option<String>,
127        },
128        UnknownError {
129            stdout: Option<String>,
130            stderr: Option<String>,
131        },
132        CoverageParseError,
133        CommandError {
134            io: Arc<io::Error>,
135        },
136    }
137
138    #[derive(Clone)]
139    pub enum CargoDocError {
140        CommandError {
141            io: Arc<io::Error>,
142        },
143        UnknownError {
144            stdout: Option<String>,
145            stderr: Option<String>,
146        }
147    }
148
149    #[derive(Clone)]
150    pub enum LintingError {
151        CommandError {
152            io: Arc<io::Error>,
153        },
154        UnknownError {
155            stdout: Option<String>,
156            stderr: Option<String>,
157        }
158    }
159
160    #[derive(Clone)]
161    pub enum CargoMetadataError {
162        MetadataError {
163            error: Arc<cargo_metadata::Error>,
164        },
165        CircularDependency,
166        CyclicPackageDependency,
167    }
168
169    #[derive(Clone)]
170    pub enum BuildError {
171        CommandError {
172            io: Arc<io::Error>,
173        },
174        BuildFailed {
175            stderr: String,
176        },
177    }
178}
179
180error_tree!{
181
182    #[derive(Clone)]
183    pub enum CrateError {
184        CargoPublishFailedForCrateWithExitCode {
185            crate_name:    String,
186            crate_version: semver::Version,
187            exit_code:     Option<i32>,
188        },
189        FailedtoRunCargoPublish {
190            crate_name:    String,
191            crate_version: semver::Version,
192            io_err:        Arc<io::Error>,
193        },
194        FailedCratesIoCheck {
195            crate_name:    String,
196            crate_version: semver::Version,
197            error:         Arc<reqwest::Error>,
198        },
199        LockfileParseFailed {
200            path:    PathBuf,
201            message: String,
202        },
203        // Error indicating that a file was not found.
204        FileNotFound {
205            missing_file: PathBuf,
206        },
207
208        // Error indicating that a directory was not found.
209        DirectoryNotFound {
210            missing_directory: PathBuf,
211        },
212
213        FailedToGetFileNameForPath {
214            path: PathBuf,
215        },
216
217        DirectoryError(DirectoryError),
218        CargoTomlError(CargoTomlError),
219
220        IoError {
221            io_error: Arc<io::Error>,
222            context: String,
223        },
224    }
225}
226
227error_tree!{
228
229    #[derive(Clone)]
230    pub enum WatchError {
231        NotifyError(Arc<notify::Error>),
232        IoError {
233            io:      Arc<io::Error>,
234            context: String,
235        },
236        ChannelRecvError(std::sync::mpsc::RecvError),
237    }
238
239    #[derive(Clone)]
240    pub enum GitError {
241        FailedToRunGitStatusMakeSureGitIsInstalled,
242        WorkingDirectoryIsNotCleanAborting,
243        IoError {
244            io:      Arc<io::Error>,
245            context: String,
246        }
247    }
248
249    // Enum representing possible errors in the `workspace-detail` crate.
250    #[derive(Clone)]
251    pub enum WorkspaceError {
252        CycleDetectedInWorkspaceDependencyGraph {
253            cycle_node_id: NodeIndex,
254        },
255        ActuallyInSingleCrate {
256            path: PathBuf,
257        },
258        GitError(GitError),
259        CrateError(CrateError),
260        CratePinFailed {
261            crate_path: PathBuf,
262            source:     Box<CrateError>,
263        },
264
265        TokioJoinError {
266            join_error: Arc<tokio::task::JoinError>,
267        },
268        IoError {
269            io_error: Arc<io::Error>,
270            context:  String,
271        },
272        InvalidLockfile {
273            path:    PathBuf,
274            message: String,
275        },
276
277        // Error indicating that a file was not found.
278        FileNotFound {
279            missing_file: PathBuf,
280        },
281
282        InvalidWorkspace {
283            invalid_workspace_path: PathBuf,
284        },
285
286        CargoDocError(CargoDocError),
287        CrateWriteError(CrateWriteError),
288        ReadmeWriteError(ReadmeWriteError),
289        TokioError(TokioError),
290        CargoMetadataError(CargoMetadataError),
291        CircularDependency {
292            // To store the detected cycles
293            detected_cycles: Vec<Vec<String>>,
294        },  
295        CoverageParseError,
296        DirectoryRemovalError,
297        FileRemovalError,
298        InvalidCargoToml(CargoTomlError),
299        CargoTomlWriteError(CargoTomlWriteError),
300        LintingError(LintingError),
301        MultipleErrors(Vec<WorkspaceError>),
302        TestCoverageError(TestCoverageError),
303        TestFailure(TestFailure),
304        WatchError(WatchError),
305        BuildError(BuildError),
306        FileError(FileError),
307        DirectoryError(DirectoryError),
308        WorkspaceNotReadyForCargoPublish,
309        FileWatchError,
310        TestTimeout,
311    }
312}
313
314impl From<tokio::task::JoinError> for WorkspaceError {
315    fn from(join_error: tokio::task::JoinError) -> Self {
316        WorkspaceError::TokioJoinError {
317            join_error: Arc::new(join_error),
318        }
319    }
320}
321
322impl From<io::Error> for WorkspaceError {
323    fn from(io_error: io::Error) -> Self {
324        WorkspaceError::IoError {
325            io_error: Arc::new(io_error),
326            context: "no explicit context".to_string()
327        }
328    }
329}
330
331impl fmt::Display for WorkspaceError {
332    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
333        write!(f, "{:#?}", self)
334    }
335}
336
337impl CargoMetadataError {
338
339    pub fn is_cyclic_package_dependency_error(&self) -> bool {
340        self.to_string().contains("cyclic package dependency")
341    }
342}
343
344impl fmt::Display for CargoMetadataError {
345    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
346        write!(f, "{:#?}", self)
347    }
348}