mtag_cli/error.rs
1use std::{io, path::PathBuf};
2
3use thiserror::Error;
4
5/// Result alias used throughout the library.
6pub type MtagResult<T> = Result<T, MtagError>;
7
8/// Errors that can occur while scanning, planning, or executing an organization run.
9#[derive(Debug, Error)]
10pub enum MtagError {
11 /// A source directory could not be read during recursive scanning.
12 #[error("failed to scan music folder `{path}`: {source}")]
13 ReadDirectory {
14 /// Directory that could not be read.
15 path: PathBuf,
16 /// Underlying filesystem error.
17 #[source]
18 source: io::Error,
19 },
20 /// A file type could not be inspected.
21 #[error("failed to inspect file type `{path}`: {source}")]
22 InspectFileType {
23 /// File whose type could not be inspected.
24 path: PathBuf,
25 /// Underlying filesystem or MIME-sniffing error.
26 #[source]
27 source: io::Error,
28 },
29 /// Audio metadata could not be read.
30 #[error("failed to read metadata from `{path}`: {source}")]
31 ReadMetadata {
32 /// Audio file whose tags could not be read.
33 path: PathBuf,
34 /// Underlying Lofty error.
35 #[source]
36 source: lofty::LoftyError,
37 },
38 /// The audio file had no readable tag block.
39 #[error("no readable tags found in `{path}`")]
40 MissingTags {
41 /// File that had no readable tags.
42 path: PathBuf,
43 },
44 /// A source or destination path had no final file-name component.
45 #[error("path `{path}` has no file name")]
46 MissingFileName {
47 /// Path missing a file name.
48 path: PathBuf,
49 },
50 /// The destination file already exists and the selected conflict policy forbids overwriting.
51 #[error("destination already exists `{path}`")]
52 DestinationExists {
53 /// Destination path that already exists.
54 path: PathBuf,
55 },
56 /// A conflict strategy string could not be parsed.
57 #[error("invalid conflict strategy `{value}`")]
58 InvalidConflictStrategy {
59 /// User-provided strategy value.
60 value: String,
61 },
62 /// A template references an unsupported variable.
63 #[error("invalid template variable `{variable}`")]
64 InvalidTemplateVariable {
65 /// Unknown template variable name without braces.
66 variable: String,
67 },
68 /// A template contains an opening brace without a matching closing brace.
69 #[error("unclosed template variable in `{template}`")]
70 UnclosedTemplateVariable {
71 /// Template segment that could not be parsed.
72 template: String,
73 },
74 /// A filesystem operation failed while copying, moving, or preparing destination directories.
75 #[error("failed to {operation} `{from}` to `{to}`: {source}")]
76 FileOperation {
77 /// Human-readable operation name.
78 operation: &'static str,
79 /// Source file involved in the operation.
80 from: PathBuf,
81 /// Destination file involved in the operation.
82 to: PathBuf,
83 /// Underlying filesystem error.
84 #[source]
85 source: io::Error,
86 },
87}