workspacer_errors/
errors.rs

1// ---------------- [ File: workspacer-errors/src/errors.rs ]
2crate::ix!();
3
4error_tree!{
5
6    #[derive(Clone)]
7    #[allow(non_camel_case_types)]
8    pub enum SourceFileRegistrationError {
9        EncounteredAnXMacroAfterWeAlreadySawANonAttributeItem {
10            file_path:      PathBuf,
11            offending_item: String,
12        },
13        CrateError(CrateError),
14        LibRsSyntaxErrors { 
15            parse_errors: Vec<String> 
16        },
17        LibRsParseTreeError {
18            file_path: PathBuf,
19        },
20        FoundAnUnhandlableTopLevelMacroCallWithAttributes,
21        MultipleItemsInXMacroUnsupported { 
22            chunk: String 
23        },
24        FoundARawModNameWhichWeDontHandlePleaseRemoveOrUnifyWithXMacros { 
25            mod_name:  String 
26        },
27        EncounteredAnXMacroAfterWeAlreadySawANonAttributeItem_NotRewritingSafely,
28    }
29
30    #[derive(Clone)]
31    pub enum CargoTomlWriteError {
32        WriteWorkspaceHeaderError {
33            io: Arc<io::Error>,
34        },
35        OpenWorkspaceMembersFieldError {
36            io: Arc<io::Error>,
37        },
38        WritePackageSectionError {
39            io: Arc<io::Error>,
40        },
41        WriteWorkspaceMember {
42            io: Arc<io::Error>,
43        },
44        CloseWorkspaceMembersFieldError {
45            io: Arc<io::Error>,
46        },
47        WriteError {
48            io: Arc<io::Error>,
49            cargo_toml_file: PathBuf,
50        },
51    }
52
53    #[derive(Clone)]
54    pub enum CargoTomlError {
55        TomlSerializeError {
56            message: String, 
57        },
58        IoWriteError {
59            path: PathBuf,
60            source: Arc<std::io::Error>,
61        },
62        TopLevelNotATable {
63            path: PathBuf,
64            details: String,
65        },
66        WorkspacerFallbackError(WorkspacerFallbackError),
67        ReadError {
68            path: PathBuf,
69            io:   Arc<io::Error>,
70        },
71        CargoTomlWriteError(CargoTomlWriteError),
72        MissingRequiredFieldForPublishing {
73            cargo_toml_file: PathBuf,
74            field: String,
75        },
76        MissingRequiredFieldForIntegrity {
77            cargo_toml_file: PathBuf,
78            field: String,
79        },
80        InvalidToml {
81            path:    PathBuf,
82            details: String,
83        },
84        InvalidVersionFormat {
85            cargo_toml_file: PathBuf,
86            version: String,
87        },
88        MissingPackageSection {
89            cargo_toml_file: PathBuf,
90        },
91        MissingVersionKey {
92            cargo_toml_file: PathBuf,
93        },
94        TomlParseError {
95            cargo_toml_file: PathBuf,
96            toml_parse_error: toml::de::Error,
97        },
98        TomlEditError {
99            cargo_toml_file: PathBuf,
100            toml_parse_error: toml_edit::TomlError,
101        },
102        
103        // Error indicating that a file was not found.
104        FileNotFound {
105            missing_file: PathBuf,
106        },
107
108        FileIsNotAFile {
109            invalid_path: PathBuf,
110        },
111        SemverError(Arc<semver::Error>),
112    }
113
114    #[derive(Clone)]
115    pub enum TestFailure {
116        UnknownError {
117            stdout: Option<String>,
118            stderr: Option<String>,
119        }
120    }
121
122    #[derive(Clone)]
123    pub enum TokioError {
124        JoinError {
125            join_error: Arc<tokio::task::JoinError>,
126        },
127    }
128
129    #[derive(Clone)]
130    pub enum DirectoryError {
131        CreateDirAllError {
132            io: Arc<io::Error>,
133        },
134        ReadDirError {
135            io: Arc<io::Error>,
136        },
137        GetNextEntryError {
138            io: Arc<io::Error>,
139        },
140    }
141
142    #[derive(Clone)]
143    pub enum ReadmeWriteError {
144        AiReadmeWriterError,
145        WriteBlankReadmeError {
146            io: Arc<io::Error>,
147        },
148    }
149
150    #[derive(Clone)]
151    pub enum CrateWriteError {
152        ReadmeWriteError(ReadmeWriteError),
153        WriteDummyMainError {
154            io: Arc<io::Error>,
155        },
156        WriteDummyTestError {
157            io: Arc<io::Error>,
158        },
159        WriteLibRsFileError {
160            io: Arc<io::Error>,
161        },
162        WriteMainFnError {
163            io: Arc<io::Error>,
164        },
165    }
166
167    #[derive(Clone)]
168    pub enum TestCoverageError {
169        TestFailure {
170            stdout: Option<String>,
171            stderr: Option<String>,
172        },
173        UnknownError {
174            stdout: Option<String>,
175            stderr: Option<String>,
176        },
177        CoverageParseError,
178        CommandError {
179            io: Arc<io::Error>,
180        },
181    }
182
183    #[derive(Clone)]
184    pub enum CargoDocError {
185        CommandError {
186            io: Arc<io::Error>,
187        },
188        UnknownError {
189            stdout: Option<String>,
190            stderr: Option<String>,
191        }
192    }
193
194    #[derive(Clone)]
195    pub enum LintingError {
196        CommandError {
197            io: Arc<io::Error>,
198        },
199        UnknownError {
200            stdout: Option<String>,
201            stderr: Option<String>,
202        }
203    }
204
205    #[derive(Clone)]
206    pub enum CargoMetadataError {
207        MetadataError {
208            error: Arc<cargo_metadata::Error>,
209        },
210        CircularDependency,
211        CyclicPackageDependency,
212    }
213
214    #[derive(Clone)]
215    pub enum BuildError {
216        CommandError {
217            io: Arc<io::Error>,
218        },
219        BuildFailed {
220            stderr: String,
221        },
222    }
223}
224
225error_tree!{
226
227    #[derive(Clone)]
228    pub enum CrateError {
229        CrateVersionNotFound,
230        CargoMetadataError(CargoMetadataError),
231        CargoTomlIsLocked,
232        CouldNotLockMockCargoTomlInVersion,
233        CouldNotSetPackageVersionBecausePackageIsNotATable,
234        SimulatedIntegrityFailureInMockCrate,
235        SimulatedInvalidVersionFormat,
236        SemverError(Arc<semver::Error>),
237
238        ReadmeWriteError(ReadmeWriteError),
239
240        // Indicates that the crate's `is_private()` check returned `true`, so
241        // the crate is not publishable.
242        CrateIsPrivate {
243            crate_path: PathBuf,
244        },
245        SortAndFormatImportsInTextError {
246            message: String,
247        },
248        FailedToRunCargoPublish {
249            crate_name:    String,
250            crate_version: semver::Version,
251            io_err:        Arc<std::io::Error>,
252        },
253        CargoPublishFailedForCrateWithExitCode {
254            crate_name:    String,
255            crate_version: semver::Version,
256            exit_code:     Option<i32>,
257        },
258        FailedtoRunCargoPublish {
259            crate_name:    String,
260            crate_version: semver::Version,
261            io_err:        Arc<io::Error>,
262        },
263        CrateAlreadyPublishedOnCratesIo {
264            crate_name:    String,
265            crate_version: semver::Version,
266        },
267        FailedCratesIoCheck {
268            crate_name:    String,
269            crate_version: semver::Version,
270            error:         Arc<reqwest::Error>,
271        },
272        LockfileParseFailed {
273            path:    PathBuf,
274            message: String,
275        },
276        // Error indicating that a file was not found.
277        FileNotFound {
278            missing_file: PathBuf,
279        },
280
281        // Error indicating that a directory was not found.
282        DirectoryNotFound {
283            missing_directory: PathBuf,
284        },
285
286        FailedToGetFileNameForPath {
287            path: PathBuf,
288        },
289
290        DirectoryError(DirectoryError),
291        CargoTomlError(CargoTomlError),
292
293        IoError {
294            io_error: Arc<io::Error>,
295            context: String,
296        },
297        TokioJoinError {
298            join_error: Arc<tokio::task::JoinError>,
299        },
300        BuildError(BuildError),
301        TestFailure(TestFailure),
302        WatchError(WatchError),
303
304        /// For when we can’t find a crate by name in the workspace and must error out.
305        CrateNotFoundInWorkspace {
306            crate_name: String,
307        },
308
309        /// When we’re converting a `WorkspaceError` into a `CrateError` in scenarios
310        /// where no more specific crate-oriented variant applies.
311        WorkspaceError(Box<WorkspaceError>),
312    }
313}
314
315impl From<tokio::task::JoinError> for CrateError {
316    fn from(join_error: tokio::task::JoinError) -> Self {
317        CrateError::TokioJoinError {
318            join_error: Arc::new(join_error),
319        }
320    }
321}
322
323// You may have `CrateError::IoError` or similar. We'll define a helper
324// function or `From<std::io::Error>` so we can map I/O errors with `?`.
325impl From<std::io::Error> for CrateError {
326    fn from(e: std::io::Error) -> Self {
327        // For demonstration, we wrap it in a custom variant, or if you have
328        // a preexisting IoError variant, adapt accordingly:
329        CrateError::IoError {
330            io_error: Arc::new(e),
331            context: "I/O operation failed".to_string(),
332        }
333    }
334}
335
336
337error_tree!{
338
339    #[derive(Clone)]
340    pub enum WatchError {
341        NotifyError(Arc<notify::Error>),
342        IoError {
343            io:      Arc<io::Error>,
344            context: String,
345        },
346        ChannelRecvError(std::sync::mpsc::RecvError),
347    }
348
349    #[derive(Clone)]
350    pub enum GitError {
351        FailedToRunGitStatusMakeSureGitIsInstalled,
352        WorkingDirectoryIsNotCleanAborting,
353        IoError {
354            io:      Arc<io::Error>,
355            context: String,
356        }
357    }
358
359    // Enum representing possible errors in the `workspace-detail` crate.
360    #[derive(Clone)]
361    pub enum WorkspaceError {
362        TomlSerErr(toml::ser::Error),
363        SourceFileRegistrationError(SourceFileRegistrationError),
364        CycleDetectedInWorkspaceDependencyGraph {
365            cycle_node_id: NodeIndex,
366        },
367        ActuallyInSingleCrate {
368            path: PathBuf,
369        },
370        GitError(GitError),
371        CrateError(CrateError),
372        CratePinFailed {
373            crate_path: PathBuf,
374            source:     Box<CrateError>,
375        },
376
377        TokioJoinError {
378            join_error: Arc<tokio::task::JoinError>,
379        },
380        IoError {
381            io_error: Arc<io::Error>,
382            context:  String,
383        },
384        InvalidLockfile {
385            path:    PathBuf,
386            message: String,
387        },
388
389        // Error indicating that a file was not found.
390        FileNotFound {
391            missing_file: PathBuf,
392        },
393
394        InvalidWorkspace {
395            invalid_workspace_path: PathBuf,
396        },
397
398        CargoDocError(CargoDocError),
399        CrateWriteError(CrateWriteError),
400        ReadmeWriteError(ReadmeWriteError),
401        TokioError(TokioError),
402        CargoMetadataError(CargoMetadataError),
403        CircularDependency {
404            // To store the detected cycles
405            detected_cycles: Vec<Vec<String>>,
406        },  
407        CoverageParseError,
408        DirectoryRemovalError,
409        FileRemovalError,
410        InvalidCargoToml(CargoTomlError),
411        CargoTomlWriteError(CargoTomlWriteError),
412        LintingError(LintingError),
413        MultipleErrors(Vec<WorkspaceError>),
414        TestCoverageError(TestCoverageError),
415        TestFailure(TestFailure),
416        WatchError(WatchError),
417        BuildError(BuildError),
418        FileError(FileError),
419        DirectoryError(DirectoryError),
420        WorkspaceNotReadyForCargoPublish,
421        FileWatchError,
422        TestTimeout,
423        FileFilterError,
424        MockBuildTestFailedWithStatus {
425            status: std::process::ExitStatus,
426        },
427        BumpError {
428            crate_path: PathBuf,
429            source: Box<CrateError>,
430        },
431    }
432}
433
434impl From<tokio::task::JoinError> for WorkspaceError {
435    fn from(join_error: tokio::task::JoinError) -> Self {
436        WorkspaceError::TokioJoinError {
437            join_error: Arc::new(join_error),
438        }
439    }
440}
441
442impl From<io::Error> for WorkspaceError {
443    fn from(io_error: io::Error) -> Self {
444        WorkspaceError::IoError {
445            io_error: Arc::new(io_error),
446            context: "no explicit context".to_string()
447        }
448    }
449}
450
451impl CargoMetadataError {
452
453    pub fn is_cyclic_package_dependency_error(&self) -> bool {
454        self.to_string().contains("cyclic package dependency")
455    }
456}