mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-12 13:42:34 +00:00
Change errors
Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
This commit is contained in:
parent
5f8e114f8e
commit
8a09b90811
4 changed files with 24 additions and 23 deletions
18
src/error.rs
18
src/error.rs
|
@ -1,6 +1,6 @@
|
|||
/// Errors that could occur within Lofty.
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum Error {
|
||||
pub enum LoftyError {
|
||||
/// Unknown file extension.
|
||||
#[error("Failed to guess the metadata format based on the file extension.")]
|
||||
UnknownFileExtension,
|
||||
|
@ -38,9 +38,6 @@ pub enum Error {
|
|||
/// Any error from [`mp4ameta`]
|
||||
#[error(transparent)]
|
||||
Mp4Tag(#[from] mp4ameta::Error),
|
||||
/// Any error from [`opus_headers`]
|
||||
#[error(transparent)]
|
||||
OpusTag(#[from] opus_headers::ParseError),
|
||||
/// Any error from [`lewton`]
|
||||
#[error(transparent)]
|
||||
Lewton(#[from] lewton::VorbisError),
|
||||
|
@ -48,11 +45,14 @@ pub enum Error {
|
|||
#[error(transparent)]
|
||||
Ogg(#[from] ogg::OggReadError),
|
||||
/// Errors that arise while reading/writing to wav files
|
||||
#[error("{0}")]
|
||||
Wav(String),
|
||||
#[error("Invalid Riff file: {0}")]
|
||||
Riff(String),
|
||||
/// Errors that arise while reading/writing to opus files
|
||||
#[error("Invalid Opus file: {0}")]
|
||||
Opus(String),
|
||||
|
||||
/// Failed to convert data to a picture
|
||||
#[error("")]
|
||||
/// Arises when provided an invalid picture
|
||||
#[error("Picture contains invalid data")]
|
||||
NotAPicture,
|
||||
|
||||
/// If a string isn't Utf8
|
||||
|
@ -68,4 +68,4 @@ pub enum Error {
|
|||
}
|
||||
|
||||
/// Type for the result of tag operations.
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
pub type Result<T> = std::result::Result<T, LoftyError>;
|
||||
|
|
|
@ -126,7 +126,7 @@ mod tag;
|
|||
pub use crate::tag::{Id3Format, Tag, TagType, VorbisFormat};
|
||||
|
||||
mod error;
|
||||
pub use crate::error::{Error, Result};
|
||||
pub use crate::error::{LoftyError, Result};
|
||||
|
||||
mod components;
|
||||
pub use crate::components::tags::*;
|
||||
|
|
16
src/tag.rs
16
src/tag.rs
|
@ -1,6 +1,6 @@
|
|||
#[allow(clippy::wildcard_imports)]
|
||||
use crate::components::tags::*;
|
||||
use crate::{AudioTag, Error, Result};
|
||||
use crate::{AudioTag, LoftyError, Result};
|
||||
use std::io::Seek;
|
||||
use std::path::Path;
|
||||
|
||||
|
@ -61,8 +61,8 @@ impl Tag {
|
|||
let extension = path
|
||||
.as_ref()
|
||||
.extension()
|
||||
.ok_or(Error::UnknownFileExtension)?;
|
||||
let extension_str = extension.to_str().ok_or(Error::UnknownFileExtension)?;
|
||||
.ok_or(LoftyError::UnknownFileExtension)?;
|
||||
let extension_str = extension.to_str().ok_or(LoftyError::UnknownFileExtension)?;
|
||||
|
||||
TagType::try_from_ext(extension_str)?
|
||||
});
|
||||
|
@ -187,12 +187,12 @@ impl TagType {
|
|||
"ogg" | "oga" => Ok(Self::Vorbis(VorbisFormat::Ogg)),
|
||||
#[cfg(feature = "format-mp4")]
|
||||
"m4a" | "m4b" | "m4p" | "m4v" | "isom" | "mp4" => Ok(Self::Mp4),
|
||||
_ => Err(Error::UnsupportedFormat(ext.to_owned())),
|
||||
_ => Err(LoftyError::UnsupportedFormat(ext.to_owned())),
|
||||
}
|
||||
}
|
||||
fn try_from_sig(data: &[u8]) -> Result<Self> {
|
||||
if data.is_empty() {
|
||||
return Err(Error::EmptyFile);
|
||||
return Err(LoftyError::EmptyFile);
|
||||
}
|
||||
|
||||
match data[0] {
|
||||
|
@ -232,7 +232,7 @@ impl TagType {
|
|||
}
|
||||
|
||||
// TODO: support AIFF chunks?
|
||||
Err(Error::UnknownFormat)
|
||||
Err(LoftyError::UnknownFormat)
|
||||
},
|
||||
#[cfg(feature = "format-flac")]
|
||||
102 if data.starts_with(&FLAC) => Ok(Self::Vorbis(VorbisFormat::Flac)),
|
||||
|
@ -246,7 +246,7 @@ impl TagType {
|
|||
return Ok(Self::Vorbis(VorbisFormat::Opus));
|
||||
}
|
||||
|
||||
Err(Error::UnknownFormat)
|
||||
Err(LoftyError::UnknownFormat)
|
||||
},
|
||||
#[cfg(feature = "format-riff")]
|
||||
82 if data.starts_with(&RIFF) => {
|
||||
|
@ -280,7 +280,7 @@ impl TagType {
|
|||
},
|
||||
#[cfg(feature = "format-mp4")]
|
||||
_ if data[4..8] == FTYP => Ok(Self::Mp4),
|
||||
_ => Err(Error::UnknownFormat),
|
||||
_ => Err(LoftyError::UnknownFormat),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{Error, Result};
|
||||
use crate::{LoftyError, Result};
|
||||
|
||||
use byteorder::{BigEndian, ReadBytesExt};
|
||||
use std::borrow::Cow;
|
||||
|
@ -59,7 +59,8 @@ impl MimeType {
|
|||
}
|
||||
|
||||
impl TryFrom<&str> for MimeType {
|
||||
type Error = Error;
|
||||
type Error = LoftyError;
|
||||
|
||||
fn try_from(inp: &str) -> Result<Self> {
|
||||
Ok(match inp {
|
||||
"image/jpeg" => MimeType::Jpeg,
|
||||
|
@ -67,7 +68,7 @@ impl TryFrom<&str> for MimeType {
|
|||
"image/tiff" => MimeType::Tiff,
|
||||
"image/bmp" => MimeType::Bmp,
|
||||
"image/gif" => MimeType::Gif,
|
||||
_ => return Err(Error::UnsupportedMimeType(inp.to_owned())),
|
||||
_ => return Err(LoftyError::UnsupportedMimeType(inp.to_owned())),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -387,7 +388,7 @@ impl Picture {
|
|||
}
|
||||
}
|
||||
|
||||
Err(Error::InvalidData)
|
||||
Err(LoftyError::NotAPicture)
|
||||
}
|
||||
/// Convert the [`Picture`] back to an APEv2 byte vec:
|
||||
///
|
||||
|
@ -480,6 +481,6 @@ impl Picture {
|
|||
}
|
||||
}
|
||||
|
||||
Err(Error::InvalidData)
|
||||
Err(LoftyError::NotAPicture)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue