Skip to main content

selene_core/
errors.rs

1use std::path::PathBuf;
2
3use image::ImageError;
4use lofty::error::LoftyError;
5use lunar_lib::database::{DatabaseError, TransactionError};
6use thiserror::Error;
7
8use crate::media_container::{Codec, ContainerFormat};
9
10#[derive(Debug, Error)]
11pub enum CodecError {
12    #[error("Unknown or unsupported codec: {0}")]
13    Unknown(String),
14
15    #[error("Codec '{0:?}' is missing an encoder")]
16    NoEncoder(Codec),
17
18    #[error("A codec is missing a symphonia decoder")]
19    NoDecoder,
20
21    #[error("Codec '{0:?}' is an unsupported codec")]
22    UnsupportedCodec(Codec),
23}
24
25#[derive(Debug, Error)]
26pub enum ContainerError {
27    #[error("IoError: {0}")]
28    Io(#[from] std::io::Error),
29
30    #[error("Codec Error: {0}")]
31    Codec(#[from] CodecError),
32
33    #[error("Symphonia Error: {0}")]
34    Symphonia(#[from] symphonia::core::errors::Error),
35
36    #[error("File '{0}' has no tracks/streams")]
37    NoStream(PathBuf),
38
39    #[error("File '{0}' has an unsupported container")]
40    InvalidSource(PathBuf),
41
42    #[error("'{0:?}' is an unsupported container")]
43    UnsupportedContainer(ContainerFormat),
44
45    #[error("Couldn't find sample rate")]
46    NoSampleRate,
47
48    #[error("Couldn't find channel count'")]
49    NoChannelCount,
50}
51
52#[derive(Error, Debug)]
53pub enum LibraryError {
54    #[error(
55        "Failed to update library because no library directory set (Try 'musicmanager library set --help)"
56    )]
57    NoLibrary,
58}
59
60#[derive(Debug, Error)]
61pub enum ExtractError {
62    #[error("IoError: {0}")]
63    Io(#[from] std::io::Error),
64
65    #[error("LoftyError: {0}")]
66    Lofty(#[from] LoftyError),
67
68    #[error("DatabaseError: {0}")]
69    Database(#[from] DatabaseError),
70
71    #[error("Transaction Error: {0}")]
72    Transaction(#[from] TransactionError),
73
74    #[error("Container Error: {0}")]
75    Container(#[from] ContainerError),
76
77    #[error("Format Error: {0}")]
78    Format(#[from] lunar_lib::formatter::FormatError),
79
80    #[error("InvalidContainer Error")]
81    InvalidContainer,
82}
83
84#[derive(Debug, Error)]
85pub enum OrphanRelinkError {
86    #[error("IoError: {0}")]
87    Io(#[from] std::io::Error),
88
89    #[error("Database Error: {0}")]
90    Database(#[from] DatabaseError),
91
92    #[error("Transaction Error: {0}")]
93    Transaction(#[from] TransactionError),
94
95    #[error("Library Error: {0}")]
96    Library(#[from] LibraryError),
97}
98
99#[derive(Debug, Error)]
100pub enum ImportError {
101    #[error("IoError: {0}")]
102    Io(#[from] std::io::Error),
103
104    #[error("Lofty Error: {0}")]
105    Lofty(#[from] LoftyError),
106
107    #[error("Codec Error: {0}")]
108    Codec(#[from] CodecError),
109
110    #[error("Database Error: {0}")]
111    Database(#[from] DatabaseError),
112
113    #[error("Transaction Error: {0}")]
114    Transaction(#[from] TransactionError),
115
116    #[error("Container Error: {0}")]
117    Container(#[from] ContainerError),
118
119    #[error("Metadata Error: {0}")]
120    Metadata(#[from] MetadataError),
121
122    #[error("Library Error: {0}")]
123    Library(#[from] LibraryError),
124}
125
126#[derive(Debug, Error)]
127pub enum MetadataError {
128    #[error("IoError: {0}")]
129    Io(#[from] std::io::Error),
130
131    #[error("Database Error: {0}")]
132    Database(#[from] DatabaseError),
133
134    #[error("Transaction Error: {0}")]
135    Transaction(#[from] TransactionError),
136
137    #[error("Lofty Error: {0}")]
138    Lofty(#[from] LoftyError),
139
140    #[error("Image Error: {0}")]
141    Image(#[from] ImageError),
142}