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
22impl From<surrealdb::Error> for Error {
23 #[inline]
24 fn from(err: surrealdb::Error) -> Self {
25 Self::DbError(Box::new(err))
26 }
27}
28
29#[derive(Error, Debug)]
30pub enum SongIOError {
31 #[error("IO error: {0}")]
32 FsError(#[from] std::io::Error),
33 #[error("Lofty error: {0}")]
34 LoftyError(#[from] lofty::error::LoftyError),
35 #[error("Song missing audio tags")]
36 MissingTags,
37 #[error("File not found: {0}")]
38 FileNotFound(PathBuf),
39 #[error("Song already exists in the database")]
40 SongExists,
41 #[error("couldn't read duration from metadata")]
42 DurationReadError,
43}
44
45pub type StorageResult<T> = std::result::Result<T, Error>;