mecomp_storage/
errors.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std::path::PathBuf;

use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
    #[cfg(feature = "db")]
    #[error("SurrealDB error: {0}")]
    DbError(#[from] surrealdb::Error),
    #[error("Failed to set database path to {0}")]
    DbPathSetError(PathBuf),
    #[error("Item is missing an Id.")]
    NoId,
    #[error("Item not found.")]
    NotFound,
    #[error("Song IO error: {0}")]
    SongIOError(#[from] SongIOError),
    #[error("Item not created.")]
    NotCreated,
}

#[derive(Error, Debug)]
pub enum SongIOError {
    #[error("IO error: {0}")]
    FsError(#[from] std::io::Error),
    #[error("Lofty error: {0}")]
    LoftyError(#[from] lofty::error::LoftyError),
    #[error("Song missing audio tags")]
    MissingTags,
    #[error("File not found: {0}")]
    FileNotFound(PathBuf),
    #[error("Song already exists in the database")]
    SongExists,
    #[error("couldn't read duration from metadata")]
    DurationReadError,
}

pub type StorageResult<T> = std::result::Result<T, Error>;