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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
use std::fmt::{Display, Formatter};
use ogg_pager::PageError;
pub type Result<T> = std::result::Result<T, LoftyError>;
#[derive(Debug)]
pub enum LoftyError {
BadExtension(String),
UnknownFormat,
EmptyFile,
TooMuchData,
#[cfg(feature = "id3v2")]
BadPictureFormat(String),
NotAPicture,
UnsupportedPicture,
UnsupportedTag,
FakeTag,
TextDecode(&'static str),
Id3v2(&'static str),
BadId3v2Version(u8, u8),
#[cfg(feature = "id3v2")]
BadFrameID,
#[cfg(feature = "id3v2")]
BadFrameLength,
#[cfg(feature = "id3v2")]
BadSyncText,
BadAtom(&'static str),
Wav(&'static str),
Aiff(&'static str),
Flac(&'static str),
Opus(&'static str),
Vorbis(&'static str),
Ogg(&'static str),
Mp3(&'static str),
Mp4(&'static str),
Ape(&'static str),
OggPage(ogg_pager::PageError),
FromUtf8(std::string::FromUtf8Error),
Io(std::io::Error),
}
impl Display for LoftyError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
LoftyError::OggPage(ref err) => write!(f, "{}", err),
LoftyError::FromUtf8(ref err) => write!(f, "{}", err),
LoftyError::Io(ref err) => write!(f, "{}", err),
LoftyError::BadExtension(ext) => write!(f, "Found unknown file extension \"{}\"", ext),
LoftyError::UnknownFormat => {
write!(f, "No format could be determined from the provided file")
},
LoftyError::EmptyFile => write!(f, "File contains no data"),
LoftyError::TooMuchData => write!(
f,
"An abnormally large amount of data was provided, and an overflow occurred"
),
LoftyError::NotAPicture => write!(f, "Picture: Encountered invalid data"),
LoftyError::UnsupportedPicture => {
write!(f, "Picture: attempted to write an unsupported picture")
},
LoftyError::UnsupportedTag => write!(
f,
"Attempted to write a tag to a format that does not support it"
),
LoftyError::FakeTag => write!(f, "Reading: Expected a tag, found invalid data"),
#[cfg(feature = "id3v2")]
LoftyError::BadPictureFormat(format) => {
write!(f, "Picture: Found unexpected format \"{}\"", format)
},
LoftyError::TextDecode(message) => write!(f, "Text decoding: {}", message),
LoftyError::Id3v2(message) => write!(f, "ID3v2: {}", message),
LoftyError::BadId3v2Version(major, minor) => write!(
f,
"ID3v2: Found an invalid version (v{}.{}), expected any major revision in: (2, 3, \
4)",
major, minor
),
#[cfg(feature = "id3v2")]
LoftyError::BadFrameID => write!(f, "ID3v2: Failed to parse a frame ID"),
#[cfg(feature = "id3v2")]
LoftyError::BadFrameLength => write!(
f,
"ID3v2: Frame isn't long enough to extract the necessary information"
),
#[cfg(feature = "id3v2")]
LoftyError::BadSyncText => write!(f, "ID3v2: Encountered invalid data in SYLT frame"),
LoftyError::BadAtom(message) => write!(f, "MP4 Atom: {}", message),
LoftyError::Wav(message) => write!(f, "WAV: {}", message),
LoftyError::Aiff(message) => write!(f, "AIFF: {}", message),
LoftyError::Flac(message) => write!(f, "FLAC: {}", message),
LoftyError::Opus(message) => write!(f, "Opus: {}", message),
LoftyError::Vorbis(message) => write!(f, "OGG Vorbis: {}", message),
LoftyError::Ogg(message) => write!(f, "OGG: {}", message),
LoftyError::Mp3(message) => write!(f, "MP3: {}", message),
LoftyError::Mp4(message) => write!(f, "MP4: {}", message),
LoftyError::Ape(message) => write!(f, "APE: {}", message),
}
}
}
impl std::error::Error for LoftyError {}
impl From<ogg_pager::PageError> for LoftyError {
fn from(input: PageError) -> Self {
LoftyError::OggPage(input)
}
}
impl From<std::io::Error> for LoftyError {
fn from(input: std::io::Error) -> Self {
LoftyError::Io(input)
}
}
impl From<std::string::FromUtf8Error> for LoftyError {
fn from(input: std::string::FromUtf8Error) -> Self {
LoftyError::FromUtf8(input)
}
}