mecomp_storage/
errors.rs

1use std::path::PathBuf;
2
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum Error {
7    #[cfg(feature = "db")]
8    #[error("SurrealDB error: {0}")]
9    DbError(#[from] Box<surrealdb::Error>),
10    #[error("Failed to set database path to {0}")]
11    DbPathSetError(PathBuf),
12    #[error("Item is missing an Id.")]
13    NoId,
14    #[error("Item not found.")]
15    NotFound,
16    #[error("Song IO error: {0}")]
17    SongIOError(#[from] SongIOError),
18    #[error("Item not created.")]
19    NotCreated,
20}
21
22#[cfg(feature = "db")]
23impl From<surrealdb::Error> for Error {
24    #[inline]
25    fn from(err: surrealdb::Error) -> Self {
26        Self::DbError(Box::new(err))
27    }
28}
29
30#[derive(Error, Debug)]
31pub enum SongIOError {
32    #[error("IO error: {0}")]
33    FsError(#[from] std::io::Error),
34    #[error("Lofty error: {0}")]
35    LoftyError(#[from] lofty::error::LoftyError),
36    #[error("Song missing audio tags")]
37    MissingTags,
38    #[error("File not found: {0}")]
39    FileNotFound(PathBuf),
40    #[error("Song already exists in the database")]
41    SongExists,
42    #[error("couldn't read duration from metadata")]
43    DurationReadError,
44}
45
46pub type StorageResult<T> = std::result::Result<T, Error>;