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.
|
/// Errors that could occur within Lofty.
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum Error {
|
pub enum LoftyError {
|
||||||
/// Unknown file extension.
|
/// Unknown file extension.
|
||||||
#[error("Failed to guess the metadata format based on the file extension.")]
|
#[error("Failed to guess the metadata format based on the file extension.")]
|
||||||
UnknownFileExtension,
|
UnknownFileExtension,
|
||||||
|
@ -38,9 +38,6 @@ pub enum Error {
|
||||||
/// Any error from [`mp4ameta`]
|
/// Any error from [`mp4ameta`]
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Mp4Tag(#[from] mp4ameta::Error),
|
Mp4Tag(#[from] mp4ameta::Error),
|
||||||
/// Any error from [`opus_headers`]
|
|
||||||
#[error(transparent)]
|
|
||||||
OpusTag(#[from] opus_headers::ParseError),
|
|
||||||
/// Any error from [`lewton`]
|
/// Any error from [`lewton`]
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Lewton(#[from] lewton::VorbisError),
|
Lewton(#[from] lewton::VorbisError),
|
||||||
|
@ -48,11 +45,14 @@ pub enum Error {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Ogg(#[from] ogg::OggReadError),
|
Ogg(#[from] ogg::OggReadError),
|
||||||
/// Errors that arise while reading/writing to wav files
|
/// Errors that arise while reading/writing to wav files
|
||||||
#[error("{0}")]
|
#[error("Invalid Riff file: {0}")]
|
||||||
Wav(String),
|
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
|
/// Arises when provided an invalid picture
|
||||||
#[error("")]
|
#[error("Picture contains invalid data")]
|
||||||
NotAPicture,
|
NotAPicture,
|
||||||
|
|
||||||
/// If a string isn't Utf8
|
/// If a string isn't Utf8
|
||||||
|
@ -68,4 +68,4 @@ pub enum Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Type for the result of tag operations.
|
/// 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};
|
pub use crate::tag::{Id3Format, Tag, TagType, VorbisFormat};
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
pub use crate::error::{Error, Result};
|
pub use crate::error::{LoftyError, Result};
|
||||||
|
|
||||||
mod components;
|
mod components;
|
||||||
pub use crate::components::tags::*;
|
pub use crate::components::tags::*;
|
||||||
|
|
16
src/tag.rs
16
src/tag.rs
|
@ -1,6 +1,6 @@
|
||||||
#[allow(clippy::wildcard_imports)]
|
#[allow(clippy::wildcard_imports)]
|
||||||
use crate::components::tags::*;
|
use crate::components::tags::*;
|
||||||
use crate::{AudioTag, Error, Result};
|
use crate::{AudioTag, LoftyError, Result};
|
||||||
use std::io::Seek;
|
use std::io::Seek;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
@ -61,8 +61,8 @@ impl Tag {
|
||||||
let extension = path
|
let extension = path
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.extension()
|
.extension()
|
||||||
.ok_or(Error::UnknownFileExtension)?;
|
.ok_or(LoftyError::UnknownFileExtension)?;
|
||||||
let extension_str = extension.to_str().ok_or(Error::UnknownFileExtension)?;
|
let extension_str = extension.to_str().ok_or(LoftyError::UnknownFileExtension)?;
|
||||||
|
|
||||||
TagType::try_from_ext(extension_str)?
|
TagType::try_from_ext(extension_str)?
|
||||||
});
|
});
|
||||||
|
@ -187,12 +187,12 @@ impl TagType {
|
||||||
"ogg" | "oga" => Ok(Self::Vorbis(VorbisFormat::Ogg)),
|
"ogg" | "oga" => Ok(Self::Vorbis(VorbisFormat::Ogg)),
|
||||||
#[cfg(feature = "format-mp4")]
|
#[cfg(feature = "format-mp4")]
|
||||||
"m4a" | "m4b" | "m4p" | "m4v" | "isom" | "mp4" => Ok(Self::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> {
|
fn try_from_sig(data: &[u8]) -> Result<Self> {
|
||||||
if data.is_empty() {
|
if data.is_empty() {
|
||||||
return Err(Error::EmptyFile);
|
return Err(LoftyError::EmptyFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
match data[0] {
|
match data[0] {
|
||||||
|
@ -232,7 +232,7 @@ impl TagType {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support AIFF chunks?
|
// TODO: support AIFF chunks?
|
||||||
Err(Error::UnknownFormat)
|
Err(LoftyError::UnknownFormat)
|
||||||
},
|
},
|
||||||
#[cfg(feature = "format-flac")]
|
#[cfg(feature = "format-flac")]
|
||||||
102 if data.starts_with(&FLAC) => Ok(Self::Vorbis(VorbisFormat::Flac)),
|
102 if data.starts_with(&FLAC) => Ok(Self::Vorbis(VorbisFormat::Flac)),
|
||||||
|
@ -246,7 +246,7 @@ impl TagType {
|
||||||
return Ok(Self::Vorbis(VorbisFormat::Opus));
|
return Ok(Self::Vorbis(VorbisFormat::Opus));
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(Error::UnknownFormat)
|
Err(LoftyError::UnknownFormat)
|
||||||
},
|
},
|
||||||
#[cfg(feature = "format-riff")]
|
#[cfg(feature = "format-riff")]
|
||||||
82 if data.starts_with(&RIFF) => {
|
82 if data.starts_with(&RIFF) => {
|
||||||
|
@ -280,7 +280,7 @@ impl TagType {
|
||||||
},
|
},
|
||||||
#[cfg(feature = "format-mp4")]
|
#[cfg(feature = "format-mp4")]
|
||||||
_ if data[4..8] == FTYP => Ok(Self::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 byteorder::{BigEndian, ReadBytesExt};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
@ -59,7 +59,8 @@ impl MimeType {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<&str> for MimeType {
|
impl TryFrom<&str> for MimeType {
|
||||||
type Error = Error;
|
type Error = LoftyError;
|
||||||
|
|
||||||
fn try_from(inp: &str) -> Result<Self> {
|
fn try_from(inp: &str) -> Result<Self> {
|
||||||
Ok(match inp {
|
Ok(match inp {
|
||||||
"image/jpeg" => MimeType::Jpeg,
|
"image/jpeg" => MimeType::Jpeg,
|
||||||
|
@ -67,7 +68,7 @@ impl TryFrom<&str> for MimeType {
|
||||||
"image/tiff" => MimeType::Tiff,
|
"image/tiff" => MimeType::Tiff,
|
||||||
"image/bmp" => MimeType::Bmp,
|
"image/bmp" => MimeType::Bmp,
|
||||||
"image/gif" => MimeType::Gif,
|
"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:
|
/// 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