anni_repo/
error.rs

1use std::path::PathBuf;
2
3use crate::models::TagRef;
4
5#[derive(thiserror::Error, Debug)]
6pub enum Error {
7    #[error("invalid {target} toml: {err:?}\n{input}")]
8    TomlParseError {
9        target: &'static str,
10        input: String,
11        err: toml::de::Error,
12    },
13
14    #[error("album with the same catalog already exists: {0}")]
15    RepoAlbumExists(String),
16
17    #[error("duplicated album: {0}")]
18    RepoDuplicatedAlbumId(String),
19
20    #[error("failed to load album {album:?} in repository")]
21    RepoAlbumLoadError { album: String },
22
23    #[error("failed to load tags from {file:?}")]
24    RepoTagLoadError { file: PathBuf },
25
26    #[error("undefined tags {0:?}")]
27    RepoTagsUndefined(Vec<TagRef<'static>>),
28
29    #[error("unknown tag type: {0}")]
30    RepoTagUnknownType(String),
31
32    #[error("duplicated tag: {0}")]
33    RepoTagDuplicated(TagRef<'static>),
34
35    #[error("repo is locked by another instance")]
36    RepoInUse,
37
38    #[error("invalid track type: {0}")]
39    InvalidTrackType(String),
40
41    #[error("invalid date: {0}")]
42    InvalidDate(String),
43
44    #[error(transparent)]
45    IOError(#[from] std::io::Error),
46
47    #[cfg(any(feature = "db-read", feature = "db-write"))]
48    #[error(transparent)]
49    SqliteError(#[from] rusqlite::Error),
50
51    #[cfg(feature = "db-read")]
52    #[error(transparent)]
53    SqliteDeserializeError(#[from] serde_rusqlite::Error),
54
55    #[cfg(feature = "git")]
56    #[error(transparent)]
57    GitError(#[from] git2::Error),
58
59    #[error("multiple errors detected: {0:#?}")]
60    MultipleErrors(Vec<Error>),
61}
62
63#[cfg(feature = "apply")]
64#[derive(thiserror::Error, Debug)]
65pub enum AlbumApplyError {
66    #[cfg(feature = "apply")]
67    #[error("Disc count mismatch when applying album {path}: expected {expected}, got {actual}")]
68    DiscMismatch {
69        path: PathBuf,
70        expected: usize,
71        actual: usize,
72    },
73
74    #[error("Track count mismatch when applying album {path}: expected {expected}, got {actual}")]
75    TrackMismatch {
76        path: PathBuf,
77        expected: usize,
78        actual: usize,
79    },
80
81    #[error("Invalid disc folder name {0} got.")]
82    InvalidDiscFolder(PathBuf),
83
84    #[error("Missing cover file at: {0}")]
85    MissingCover(PathBuf),
86
87    #[error(transparent)]
88    IOError(#[from] std::io::Error),
89
90    #[error(transparent)]
91    FlacParseError(#[from] anni_flac::error::FlacError),
92}