From e06fd5868d47e3e075bf9795947a2db3e0896d8f Mon Sep 17 00:00:00 2001 From: atok Date: Mon, 8 Jan 2024 17:25:41 +0100 Subject: [PATCH] Rework error wrapping --- symphonia-bundle-mp3/src/layer3/mod.rs | 5 +- symphonia-bundle-mp3/src/lib.rs | 2 + symphonia-check/src/main.rs | 5 +- symphonia-codec-aac/src/lib.rs | 2 + symphonia-codec-adpcm/src/lib.rs | 2 + symphonia-codec-alac/src/lib.rs | 2 + symphonia-codec-vorbis/src/floor.rs | 7 +- symphonia-codec-vorbis/src/lib.rs | 2 + symphonia-codec-vorbis/src/residue.rs | 5 +- symphonia-core/src/errors.rs | 285 ++++--------------- symphonia-core/src/io/bit.rs | 11 +- symphonia-core/src/io/buf_reader.rs | 5 +- symphonia-core/src/io/media_source_stream.rs | 9 +- symphonia-core/src/io/mod.rs | 10 +- symphonia-core/src/io/scoped_stream.rs | 5 +- symphonia-core/src/lib.rs | 4 +- symphonia-format-isomp4/src/stream.rs | 3 +- symphonia-format-mkv/src/demuxer.rs | 3 +- symphonia-format-mkv/src/ebml.rs | 14 +- symphonia-format-mkv/src/segment.rs | 3 +- symphonia-format-ogg/src/demuxer.rs | 4 +- symphonia-format-ogg/src/page.rs | 6 +- symphonia-format-riff/src/common.rs | 3 +- symphonia-format-wav/src/chunks.rs | 3 +- symphonia-play/src/main.rs | 5 +- 25 files changed, 119 insertions(+), 286 deletions(-) diff --git a/symphonia-bundle-mp3/src/layer3/mod.rs b/symphonia-bundle-mp3/src/layer3/mod.rs index 1108a9a3..9b19cc43 100644 --- a/symphonia-bundle-mp3/src/layer3/mod.rs +++ b/symphonia-bundle-mp3/src/layer3/mod.rs @@ -8,7 +8,8 @@ use std::fmt; use symphonia_core::audio::{AudioBuffer, Signal}; -use symphonia_core::errors::{decode_error, Error, IoErrorKind, Result}; +use symphonia_core::errors::{decode_error, Result}; +use symphonia_core::errors::SymphoniaError as Error; use symphonia_core::io::{BitReaderLtr, BufReader, ReadBitsLtr, ReadBytes}; mod bitstream; @@ -356,7 +357,7 @@ impl Layer3 { // IO error to a decode error. frame_data.granules[gr].channels[ch].rzero = match huffman_result { Ok(rzero) => rzero, - Err(Error::IoError(IoErrorKind::Other, _)) => { + Err(Error::IoError(_)) => { return decode_error("mpa: huffman decode overrun"); } Err(err) => return Err(err), diff --git a/symphonia-bundle-mp3/src/lib.rs b/symphonia-bundle-mp3/src/lib.rs index def350db..08ac92e0 100644 --- a/symphonia-bundle-mp3/src/lib.rs +++ b/symphonia-bundle-mp3/src/lib.rs @@ -14,6 +14,8 @@ #![allow(clippy::identity_op)] #![allow(clippy::manual_range_contains)] +extern crate alloc; + // Shared modules. mod common; mod header; diff --git a/symphonia-check/src/main.rs b/symphonia-check/src/main.rs index 68a84182..74153d6d 100644 --- a/symphonia-check/src/main.rs +++ b/symphonia-check/src/main.rs @@ -18,7 +18,8 @@ use std::process::{Command, Stdio}; use symphonia::core::audio::{AudioBufferRef, SampleBuffer}; use symphonia::core::codecs::{Decoder, DecoderOptions}; -use symphonia::core::errors::{Error, IoErrorKind, Result}; +use symphonia::core::errors::Result; +use symphonia::core::errors::SymphoniaError as Error; use symphonia::core::formats::{FormatOptions, FormatReader}; use symphonia::core::io::{MediaSourceStream, ReadOnlySource}; use symphonia::core::meta::MetadataOptions; @@ -396,7 +397,7 @@ fn main() { println!(); match run_test(path, &opts, &mut res) { - Err(Error::IoError(IoErrorKind::UnexpectedEof, _)) => (), + Err(Error::EndOfFile) => (), Err(err) => { eprintln!("Test interrupted by error: {}", err); std::process::exit(2); diff --git a/symphonia-codec-aac/src/lib.rs b/symphonia-codec-aac/src/lib.rs index 34c8c9f8..08ca8fad 100644 --- a/symphonia-codec-aac/src/lib.rs +++ b/symphonia-codec-aac/src/lib.rs @@ -16,6 +16,8 @@ // TODO: Remove this when refactoring AAC. #![allow(clippy::needless_range_loop)] +extern crate alloc; + mod aac; mod adts; mod common; diff --git a/symphonia-codec-adpcm/src/lib.rs b/symphonia-codec-adpcm/src/lib.rs index 4d69fe3e..079d8512 100644 --- a/symphonia-codec-adpcm/src/lib.rs +++ b/symphonia-codec-adpcm/src/lib.rs @@ -24,6 +24,8 @@ use symphonia_core::errors::{unsupported_error, Result}; use symphonia_core::formats::Packet; use symphonia_core::io::ReadBytes; +extern crate alloc; + mod codec_ima; mod codec_ms; mod common; diff --git a/symphonia-codec-alac/src/lib.rs b/symphonia-codec-alac/src/lib.rs index 1ada71ab..e43c2c72 100644 --- a/symphonia-codec-alac/src/lib.rs +++ b/symphonia-codec-alac/src/lib.rs @@ -29,6 +29,8 @@ use symphonia_core::formats::Packet; use symphonia_core::io::{BitReaderLtr, BufReader, FiniteStream, ReadBitsLtr, ReadBytes}; use symphonia_core::support_codec; +extern crate alloc; + /// Supported ALAC version. const ALAC_VERSION: u8 = 0; diff --git a/symphonia-codec-vorbis/src/floor.rs b/symphonia-codec-vorbis/src/floor.rs index 3dbfa65e..b3c14c25 100644 --- a/symphonia-codec-vorbis/src/floor.rs +++ b/symphonia-codec-vorbis/src/floor.rs @@ -8,7 +8,8 @@ use std::cmp::min; use std::collections::HashSet; -use symphonia_core::errors::{decode_error, Error, IoErrorKind, Result}; +use symphonia_core::errors::SymphoniaError as Error; +use symphonia_core::errors::{decode_error, Result}; use symphonia_core::io::{BitReaderRtl, ReadBitsRtl}; use super::codebook::VorbisCodebook; @@ -92,7 +93,7 @@ macro_rules! io_try_or_ret { // An end-of-bitstream error is classified under ErrorKind::Other. This condition // should not be treated as an error, rather, it should return from the function // immediately without error. - Err(Error::IoError(IoErrorKind::Other, _)) => return Ok(()), + Err(Error::EndOfFile) => return Ok(()), Err(e) => return Err(e.into()), } }; @@ -105,7 +106,7 @@ macro_rules! try_or_ret { // An end-of-bitstream error is classified under ErrorKind::Other. This condition // should not be treated as an error, rather, it should return from the function // immediately without error. - Err(Error::IoError(IoErrorKind::Other, _)) => return Ok(()), + Err(Error::EndOfFile) => return Ok(()), Err(e) => return Err(e), } }; diff --git a/symphonia-codec-vorbis/src/lib.rs b/symphonia-codec-vorbis/src/lib.rs index 59b53455..7726fada 100644 --- a/symphonia-codec-vorbis/src/lib.rs +++ b/symphonia-codec-vorbis/src/lib.rs @@ -16,6 +16,8 @@ // Disable to better express the specification. #![allow(clippy::collapsible_else_if)] +extern crate alloc; + use symphonia_core::audio::{AsAudioBufferRef, AudioBuffer, AudioBufferRef}; use symphonia_core::audio::{Signal, SignalSpec}; use symphonia_core::codecs::{CodecDescriptor, CodecParameters, CODEC_TYPE_VORBIS}; diff --git a/symphonia-codec-vorbis/src/residue.rs b/symphonia-codec-vorbis/src/residue.rs index 3e2f3076..5531571b 100644 --- a/symphonia-codec-vorbis/src/residue.rs +++ b/symphonia-codec-vorbis/src/residue.rs @@ -8,7 +8,8 @@ use std::cmp::min; use std::convert::TryInto; -use symphonia_core::errors::{decode_error, Error, IoErrorKind, Result}; +use symphonia_core::errors::SymphoniaError as Error; +use symphonia_core::errors::{decode_error, Result}; use symphonia_core::io::{BitReaderRtl, ReadBitsRtl}; use super::codebook::VorbisCodebook; @@ -154,7 +155,7 @@ impl Residue { Ok(_) => (), // An end-of-bitstream error is classified under ErrorKind::Other. This condition // should not be treated as an error. - Err(Error::IoError(IoErrorKind::Other, _)) => (), + Err(Error::EndOfFile) => (), Err(e) => return Err(e), }; diff --git a/symphonia-core/src/errors.rs b/symphonia-core/src/errors.rs index 65b9421c..2cf07712 100644 --- a/symphonia-core/src/errors.rs +++ b/symphonia-core/src/errors.rs @@ -7,9 +7,13 @@ //! The `errors` module defines the common error type. -use core::{error, result}; +use core::{result}; use core::fmt; -use core::fmt::{Display, Formatter}; +use core::fmt::{Display}; +use std::error::Error; +use alloc::boxed::Box; +use std::io::ErrorKind; +use std::ops::Deref; /// `SeekErrorKind` is a list of generic reasons why a seek may fail. @@ -36,191 +40,13 @@ impl SeekErrorKind { } } -#[derive(Debug)] -pub enum IoErrorKind { - /// An entity was not found, often a file. - NotFound, - /// The operation lacked the necessary privileges to complete. - PermissionDenied, - /// The connection was refused by the remote server. - ConnectionRefused, - /// The connection was reset by the remote server. - ConnectionReset, - /// The remote host is not reachable. - HostUnreachable, - /// The network containing the remote host is not reachable. - NetworkUnreachable, - /// The connection was aborted (terminated) by the remote server. - ConnectionAborted, - /// The network operation failed because it was not connected yet. - NotConnected, - /// A socket address could not be bound because the address is already in - /// use elsewhere. - AddrInUse, - /// A nonexistent interface was requested or the requested address was not - /// local. - AddrNotAvailable, - /// The system's networking is down. - NetworkDown, - /// The operation failed because a pipe was closed. - BrokenPipe, - /// An entity already exists, often a file. - AlreadyExists, - /// The operation needs to block to complete, but the blocking operation was - /// requested to not occur. - WouldBlock, - /// A filesystem object is, unexpectedly, not a directory. - /// - /// For example, a filesystem path was specified where one of the intermediate directory - /// components was, in fact, a plain file. - NotADirectory, - /// The filesystem object is, unexpectedly, a directory. - /// - /// A directory was specified when a non-directory was expected. - IsADirectory, - /// A non-empty directory was specified where an empty directory was expected. - DirectoryNotEmpty, - /// The filesystem or storage medium is read-only, but a write operation was attempted. - ReadOnlyFilesystem, - /// Loop in the filesystem or IO subsystem; often, too many levels of symbolic links. - /// - /// There was a loop (or excessively long chain) resolving a filesystem object - /// or file IO object. - /// - /// On Unix this is usually the result of a symbolic link loop; or, of exceeding the - /// system-specific limit on the depth of symlink traversal. - FilesystemLoop, - /// Stale network file handle. - /// - /// With some network filesystems, notably NFS, an open file (or directory) can be invalidated - /// by problems with the network or server. - StaleNetworkFileHandle, - /// A parameter was incorrect. - InvalidInput, - /// Data not valid for the operation were encountered. - /// - /// Unlike [`InvalidInput`], this typically means that the operation - /// parameters were valid, however the error was caused by malformed - /// input data. - /// - /// For example, a function that reads a file into a string will error with - /// `InvalidData` if the file's contents are not valid UTF-8. - /// - /// [`InvalidInput`]: std::io::ErrorKind::InvalidInput - InvalidData, - /// The I/O operation's timeout expired, causing it to be canceled. - TimedOut, - /// An error returned when an operation could not be completed because a - /// call to [`write`] returned [`Ok(0)`]. - /// - /// This typically means that an operation could only succeed if it wrote a - /// particular number of bytes but only a smaller number of bytes could be - /// written. - /// - /// [`write`]: crate::io::Write::write - /// [`Ok(0)`]: Ok - WriteZero, - /// The underlying storage (typically, a filesystem) is full. - /// - /// This does not include out of quota errors. - StorageFull, - /// Seek on unseekable file. - /// - /// Seeking was attempted on an open file handle which is not suitable for seeking - for - /// example, on Unix, a named pipe opened with `File::open`. - NotSeekable, - /// Filesystem quota was exceeded. - FilesystemQuotaExceeded, - /// File larger than allowed or supported. - /// - /// This might arise from a hard limit of the underlying filesystem or file access API, or from - /// an administratively imposed resource limitation. Simple disk full, and out of quota, have - /// their own errors. - FileTooLarge, - /// Resource is busy. - ResourceBusy, - /// Executable file is busy. - /// - /// An attempt was made to write to a file which is also in use as a running program. (Not all - /// operating systems detect this situation.) - ExecutableFileBusy, - /// Deadlock (avoided). - /// - /// A file locking operation would result in deadlock. This situation is typically detected, if - /// at all, on a best-effort basis. - Deadlock, - /// Cross-device or cross-filesystem (hard) link or rename. - CrossesDevices, - /// Too many (hard) links to the same filesystem object. - /// - /// The filesystem does not support making so many hardlinks to the same file. - TooManyLinks, - /// A filename was invalid. - /// - /// This error can also cause if it exceeded the filename length limit. - InvalidFilename, - /// Program argument list too long. - /// - /// When trying to run an external program, a system or process limit on the size of the - /// arguments would have been exceeded. - ArgumentListTooLong, - /// This operation was interrupted. - /// - /// Interrupted operations can typically be retried. - Interrupted, - - /// This operation is unsupported on this platform. - /// - /// This means that the operation can never succeed. - Unsupported, - - // ErrorKinds which are primarily categorisations for OS error - // codes should be added above. - // - /// An error returned when an operation could not be completed because an - /// "end of file" was reached prematurely. - /// - /// This typically means that an operation could only succeed if it read a - /// particular number of bytes but only a smaller number of bytes could be - /// read. - UnexpectedEof, - - /// An operation could not be completed, because it failed - /// to allocate enough memory. - OutOfMemory, - - // "Unusual" error kinds which do not correspond simply to (sets - // of) OS error codes, should be added just above this comment. - // `Other` and `Uncategorized` should remain at the end: - // - /// A custom error that does not fall under any other I/O error kind. - /// - /// This can be used to construct your own [`std::io::Error`]s that do not match any - /// [`std::io::ErrorKind`]. - /// - /// This [`std::io::ErrorKind`] is not used by the standard library. - /// - /// Errors from the standard library that do not fall under any of the I/O - /// error kinds cannot be `match`ed on, and will only match a wildcard (`_`) pattern. - /// New [`std::io::ErrorKind`]s might be added in the future for some of those. - Other, -} - -impl Display for IoErrorKind { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "{:?}", self) - } -} - -impl core::error::Error for IoErrorKind { - -} - /// `Error` provides an enumeration of all possible errors reported by Symphonia. #[derive(Debug)] -pub enum Error { - /// An IO error occured while reading, writing, or seeking the stream. - IoError(IoErrorKind, &'static str), +pub enum SymphoniaError { + /// An IO error occurred while reading, writing, or seeking the stream. + IoError(Box), + /// An IO error occurred while reading, writing, or seeking the stream that is retryable. + IoInterruptedError(Box), /// The stream contained malformed data and could not be decoded or demuxed. DecodeError(&'static str), /// The stream could not be seeked. @@ -232,104 +58,93 @@ pub enum Error { LimitError(&'static str), /// The demuxer or decoder needs to be reset before continuing. ResetRequired, + EndOfFile, + Other(&'static str), } -impl fmt::Display for Error { +impl fmt::Display for SymphoniaError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - Error::IoError(ref err, msg) => { - write!(f, "io error {:?}: {}", err, msg) - }, - Error::DecodeError(msg) => { + SymphoniaError::IoError(ref err) => { + write!(f, "io error {:?}", err) + } + SymphoniaError::IoInterruptedError(ref err) => { + write!(f, "io error {:?}", err) + } + SymphoniaError::DecodeError(msg) => { write!(f, "malformed stream: {}", msg) } - Error::SeekError(ref kind) => { + SymphoniaError::SeekError(ref kind) => { write!(f, "seek error: {}", kind.as_str()) } - Error::Unsupported(feature) => { + SymphoniaError::Unsupported(feature) => { write!(f, "unsupported feature: {}", feature) } - Error::LimitError(constraint) => { + SymphoniaError::LimitError(constraint) => { write!(f, "limit reached: {}", constraint) } - Error::ResetRequired => { + SymphoniaError::ResetRequired => { write!(f, "decoder needs to be reset") } + SymphoniaError::EndOfFile => { + write!(f, "unexpected end of file") + } + SymphoniaError::Other(msg) => { + write!(f, "other error: {}", msg) + } } } } -impl core::error::Error for Error { - fn cause(&self) -> Option<&dyn error::Error> { +impl core::error::Error for SymphoniaError { + fn source(&self) -> Option<&(dyn Error + 'static)> { match *self { - Error::IoError(ref err, _msg) => Some(err), - Error::DecodeError(_) => None, - Error::SeekError(_) => None, - Error::Unsupported(_) => None, - Error::LimitError(_) => None, - Error::ResetRequired => None, + SymphoniaError::IoError(ref err) => Some(err.deref()), + SymphoniaError::IoInterruptedError(ref err) => Some(err.deref()), + _ => None, } } } #[cfg(feature = "std")] -impl From for Error { - fn from(err: std::io::Error) -> Error { - let error_kind = match err.kind() { - std::io::ErrorKind::NotFound => IoErrorKind::NotFound, - std::io::ErrorKind::PermissionDenied => IoErrorKind::PermissionDenied, - std::io::ErrorKind::ConnectionRefused => IoErrorKind::ConnectionRefused, - std::io::ErrorKind::ConnectionReset => IoErrorKind::ConnectionReset, - std::io::ErrorKind::ConnectionAborted => IoErrorKind::ConnectionAborted, - std::io::ErrorKind::NotConnected => IoErrorKind::NotConnected, - std::io::ErrorKind::AddrInUse => IoErrorKind::AddrInUse, - std::io::ErrorKind::AddrNotAvailable => IoErrorKind::AddrNotAvailable, - std::io::ErrorKind::BrokenPipe => IoErrorKind::BrokenPipe, - std::io::ErrorKind::AlreadyExists => IoErrorKind::AlreadyExists, - std::io::ErrorKind::WouldBlock => IoErrorKind::WouldBlock, - std::io::ErrorKind::InvalidInput => IoErrorKind::InvalidInput, - std::io::ErrorKind::InvalidData => IoErrorKind::InvalidData, - std::io::ErrorKind::TimedOut => IoErrorKind::TimedOut, - std::io::ErrorKind::WriteZero => IoErrorKind::WriteZero, - std::io::ErrorKind::Interrupted => IoErrorKind::Interrupted, - std::io::ErrorKind::Unsupported => IoErrorKind::Unsupported, - std::io::ErrorKind::UnexpectedEof => IoErrorKind::UnexpectedEof, - std::io::ErrorKind::OutOfMemory => IoErrorKind::OutOfMemory, - std::io::ErrorKind::Other => IoErrorKind::Other, - _ => IoErrorKind::Other, - }; - Error::IoError(error_kind, "") +impl From for SymphoniaError { + fn from(err: std::io::Error) -> SymphoniaError { + match err.kind() { + ErrorKind::Interrupted => SymphoniaError::IoInterruptedError(Box::new(err)), + ErrorKind::UnexpectedEof => SymphoniaError::EndOfFile, + _ => SymphoniaError::IoError(Box::new(err)) + } } } -pub type Result = result::Result; +pub type Result = result::Result; /// Convenience function to create a decode error. pub fn decode_error(desc: &'static str) -> Result { - Err(Error::DecodeError(desc)) + Err(SymphoniaError::DecodeError(desc)) } /// Convenience function to create a seek error. pub fn seek_error(kind: SeekErrorKind) -> Result { - Err(Error::SeekError(kind)) + Err(SymphoniaError::SeekError(kind)) } /// Convenience function to create an unsupport feature error. pub fn unsupported_error(feature: &'static str) -> Result { - Err(Error::Unsupported(feature)) + Err(SymphoniaError::Unsupported(feature)) } /// Convenience function to create a limit error. pub fn limit_error(constraint: &'static str) -> Result { - Err(Error::LimitError(constraint)) + Err(SymphoniaError::LimitError(constraint)) } /// Convenience function to create a reset required error. pub fn reset_error() -> Result { - Err(Error::ResetRequired) + Err(SymphoniaError::ResetRequired) } /// Convenience function to create an end-of-stream error. pub fn end_of_stream_error() -> Result { - Err(Error::IoError(IoErrorKind::UnexpectedEof, "end of stream")) + Err(SymphoniaError::EndOfFile) } diff --git a/symphonia-core/src/io/bit.rs b/symphonia-core/src/io/bit.rs index f17e0ced..2f113bd5 100644 --- a/symphonia-core/src/io/bit.rs +++ b/symphonia-core/src/io/bit.rs @@ -9,10 +9,11 @@ use core::cmp::min; use crate::io::ReadBytes; use crate::util::bits::*; -use crate::errors::{Error, IoErrorKind, Result}; +use crate::errors::{Result}; +use crate::errors::SymphoniaError as Error; fn end_of_bitstream_error() -> Result { - Err(Error::IoError(IoErrorKind::Other, "unexpected end of bitstream")) + Err(Error::Other("unexpected end of bitstream")) } pub mod vlc { @@ -21,11 +22,11 @@ pub mod vlc { use core::cmp::max; use alloc::collections::{BTreeMap, VecDeque}; use alloc::vec::Vec; - use crate::errors::{IoErrorKind, Result}; - use crate::errors::Error; + use crate::errors::{Result}; + use crate::errors::SymphoniaError as Error; fn codebook_error(desc: &'static str) -> Result { - Err(Error::IoError(IoErrorKind::Other, desc)) + Err(Error::Other(desc)) } /// `BitOrder` describes the relationship between the order of bits in the provided codewords diff --git a/symphonia-core/src/io/buf_reader.rs b/symphonia-core/src/io/buf_reader.rs index 8731ac36..072912c6 100644 --- a/symphonia-core/src/io/buf_reader.rs +++ b/symphonia-core/src/io/buf_reader.rs @@ -8,11 +8,12 @@ use core::cmp; use super::{FiniteStream, ReadBytes}; -use crate::errors::{IoErrorKind, Result, Error}; +use crate::errors::{Result}; +use crate::errors::SymphoniaError as Error; #[inline(always)] fn underrun_error() -> Result { - Err(Error::IoError(IoErrorKind::UnexpectedEof, "buffer underrun")) + Err(Error::Other("buffer underrun")) } /// A `BufReader` reads bytes from a byte buffer. diff --git a/symphonia-core/src/io/media_source_stream.rs b/symphonia-core/src/io/media_source_stream.rs index 83da55b2..0f88c41b 100644 --- a/symphonia-core/src/io/media_source_stream.rs +++ b/symphonia-core/src/io/media_source_stream.rs @@ -12,12 +12,11 @@ use core::ops::Sub; use super::{IoSliceMut, Read, Seek, SeekBuffered, SeekFrom}; use super::{MediaSource, ReadBytes}; -use crate::errors::{IoErrorKind, Result}; -use crate::errors::Error; +use crate::errors::{Result, SymphoniaError}; #[inline(always)] fn end_of_stream_error() -> Result { - Err(Error::IoError(IoErrorKind::UnexpectedEof, "")) + Err(SymphoniaError::EndOfFile) } /// `MediaSourceStreamOptions` specifies the buffering behaviour of a `MediaSourceStream`. @@ -204,7 +203,7 @@ impl Read for MediaSourceStream { buf = &mut buf[count..]; self.consume(count); } - Err(Error::IoError(IoErrorKind::Interrupted, _)) => {} + Err(SymphoniaError::IoInterruptedError(_)) => {} Err(e) => return Err(e), } } @@ -326,7 +325,7 @@ impl ReadBytes for MediaSourceStream { Ok(count) => { buf = &mut buf[count..]; } - Err(Error::IoError(IoErrorKind::Interrupted, _)) => {} + Err(SymphoniaError::IoInterruptedError(_)) => {} Err(e) => return Err(e), } } diff --git a/symphonia-core/src/io/mod.rs b/symphonia-core/src/io/mod.rs index 4e33c2fb..e2f3ad51 100644 --- a/symphonia-core/src/io/mod.rs +++ b/symphonia-core/src/io/mod.rs @@ -23,7 +23,7 @@ use alloc::boxed::Box; use alloc::vec; use alloc::vec::Vec; use core::mem; -use crate::errors::{Error, IoErrorKind, Result}; +use crate::errors::{SymphoniaError, Result}; #[cfg(feature = "std")] use std::io; @@ -95,7 +95,7 @@ fn default_slow_read_to_end( let n = match r { Ok(0) => break, Ok(n) => n, - Err(Error::IoError(IoErrorKind::Interrupted, _)) => 0, // Ignored + Err(SymphoniaError::IoInterruptedError(_)) => 0, // Ignored Err(err) => return Err(err), }; @@ -117,7 +117,7 @@ fn default_read_vectored(read: F, bufs: &mut [IoSliceMut<'_>]) -> Result Read for T { fn read(&mut self, buf: &mut [u8]) -> Result { - self.read(buf).map_err(|e| { Error::from(e) }) + self.read(buf).map_err(|e| { SymphoniaError::from(e) }) } } @@ -129,7 +129,7 @@ impl Seek for T { SeekFrom::End(x) => io::SeekFrom::End(x), SeekFrom::Current(x) => io::SeekFrom::Current(x), }; - self.seek(from).map_err(|e| { Error::from(e) }) + self.seek(from).map_err(|e| { SymphoniaError::from(e) }) } } @@ -238,7 +238,7 @@ impl Read for ReadOnlySource { impl Seek for ReadOnlySource { fn seek(&mut self, _: SeekFrom) -> Result { - Err(Error::IoError(IoErrorKind::Other, "source does not support seeking")) + Err(SymphoniaError::Other("source does not support seeking")) } } diff --git a/symphonia-core/src/io/scoped_stream.rs b/symphonia-core/src/io/scoped_stream.rs index 812cfc97..3819300e 100644 --- a/symphonia-core/src/io/scoped_stream.rs +++ b/symphonia-core/src/io/scoped_stream.rs @@ -6,14 +6,13 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use core::cmp; -use crate::errors::{IoErrorKind, Result}; -use crate::errors::Error; +use crate::errors::{Result, SymphoniaError}; use super::{FiniteStream, ReadBytes, SeekBuffered}; #[inline(always)] fn out_of_bounds_error() -> Result { - Err(Error::IoError(IoErrorKind::UnexpectedEof, "out of bounds")) + Err(SymphoniaError::EndOfFile) } /// A `ScopedStream` restricts the number of bytes that may be read to an upper limit. diff --git a/symphonia-core/src/lib.rs b/symphonia-core/src/lib.rs index 7e5745ed..98d387b4 100644 --- a/symphonia-core/src/lib.rs +++ b/symphonia-core/src/lib.rs @@ -16,9 +16,7 @@ #![feature(error_in_core)] extern crate alloc; - -#[cfg(not(feature="std"))] -extern crate core as std; +extern crate core; #[cfg(feature = "std")] extern crate std; diff --git a/symphonia-format-isomp4/src/stream.rs b/symphonia-format-isomp4/src/stream.rs index ec93c475..1ac8c415 100644 --- a/symphonia-format-isomp4/src/stream.rs +++ b/symphonia-format-isomp4/src/stream.rs @@ -4,7 +4,8 @@ // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use symphonia_core::errors::{decode_error, Error, Result}; +use symphonia_core::errors::{decode_error, Result}; +use symphonia_core::errors::SymphoniaError as Error; use crate::atoms::{stsz::SampleSize, Co64Atom, MoofAtom, MoovAtom, MvexAtom, StcoAtom, TrafAtom}; diff --git a/symphonia-format-mkv/src/demuxer.rs b/symphonia-format-mkv/src/demuxer.rs index 7fdca565..54555a8f 100644 --- a/symphonia-format-mkv/src/demuxer.rs +++ b/symphonia-format-mkv/src/demuxer.rs @@ -11,8 +11,9 @@ use std::convert::TryFrom; use symphonia_core::audio::Layout; use symphonia_core::codecs::{CodecParameters, CODEC_TYPE_FLAC, CODEC_TYPE_VORBIS}; use symphonia_core::errors::{ - decode_error, end_of_stream_error, seek_error, unsupported_error, Error, Result, SeekErrorKind, + decode_error, end_of_stream_error, seek_error, unsupported_error, Result, SeekErrorKind, }; +use symphonia_core::errors::SymphoniaError as Error; use symphonia_core::formats::{ Cue, FormatOptions, FormatReader, Packet, SeekMode, SeekTo, SeekedTo, Track, }; diff --git a/symphonia-format-mkv/src/ebml.rs b/symphonia-format-mkv/src/ebml.rs index ae2bf50d..7437c2ed 100644 --- a/symphonia-format-mkv/src/ebml.rs +++ b/symphonia-format-mkv/src/ebml.rs @@ -5,7 +5,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use symphonia_core::errors::{decode_error, seek_error, Error, Result, SeekErrorKind}; +use symphonia_core::errors::{decode_error, seek_error, SymphoniaError, Result, SeekErrorKind}; use symphonia_core::io::{MediaSource, ReadBytes, SeekFrom}; use symphonia_core::util::bits::sign_extend_leq64_to_i64; @@ -376,7 +376,7 @@ impl ElementIterator { let hdr = self.current.expect("not in an element"); let value = self .try_read_data(hdr)? - .ok_or(Error::DecodeError("mkv: element has no primitive data"))?; + .ok_or(SymphoniaError::DecodeError("mkv: element has no primitive data"))?; Ok(value) } @@ -384,7 +384,7 @@ impl ElementIterator { pub(crate) fn read_u64(&mut self) -> Result { match self.read_data()? { ElementData::UnsignedInt(s) => Ok(s), - _ => Err(Error::DecodeError("mkv: expected an unsigned int")), + _ => Err(SymphoniaError::DecodeError("mkv: expected an unsigned int")), } } @@ -392,7 +392,7 @@ impl ElementIterator { pub(crate) fn read_f64(&mut self) -> Result { match self.read_data()? { ElementData::Float(s) => Ok(s), - _ => Err(Error::DecodeError("mkv: expected a float")), + _ => Err(SymphoniaError::DecodeError("mkv: expected a float")), } } @@ -400,7 +400,7 @@ impl ElementIterator { pub(crate) fn read_string(&mut self) -> Result { match self.read_data()? { ElementData::String(s) => Ok(s), - _ => Err(Error::DecodeError("mkv: expected a string")), + _ => Err(SymphoniaError::DecodeError("mkv: expected a string")), } } @@ -408,7 +408,7 @@ impl ElementIterator { pub(crate) fn read_boxed_slice(&mut self) -> Result> { match self.read_data()? { ElementData::Binary(b) => Ok(b), - _ => Err(Error::DecodeError("mkv: expected binary data")), + _ => Err(SymphoniaError::DecodeError("mkv: expected binary data")), } } @@ -469,7 +469,7 @@ impl ElementIterator { 8 => self.reader.read_be_f64()?, _ => { self.ignore_data()?; - return Err(Error::DecodeError("mkv: invalid float length")); + return Err(SymphoniaError::DecodeError("mkv: invalid float length")); } }; ElementData::Float(value) diff --git a/symphonia-format-mkv/src/segment.rs b/symphonia-format-mkv/src/segment.rs index bda51ad9..cdbc4ad0 100644 --- a/symphonia-format-mkv/src/segment.rs +++ b/symphonia-format-mkv/src/segment.rs @@ -5,7 +5,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use symphonia_core::errors::{Error, Result}; +use symphonia_core::errors::SymphoniaError as Error; +use symphonia_core::errors::{Result}; use symphonia_core::io::{BufReader, ReadBytes}; use symphonia_core::meta::{MetadataBuilder, MetadataRevision, Tag, Value}; diff --git a/symphonia-format-ogg/src/demuxer.rs b/symphonia-format-ogg/src/demuxer.rs index 4003d3db..8eda9523 100644 --- a/symphonia-format-ogg/src/demuxer.rs +++ b/symphonia-format-ogg/src/demuxer.rs @@ -8,7 +8,7 @@ use std::collections::BTreeMap; use symphonia_core::errors::{reset_error, seek_error, unsupported_error}; -use symphonia_core::errors::{Error, Result, SeekErrorKind}; +use symphonia_core::errors::{SymphoniaError, Result, SeekErrorKind}; use symphonia_core::formats::prelude::*; use symphonia_core::io::*; use symphonia_core::meta::{Metadata, MetadataLog}; @@ -48,7 +48,7 @@ impl OggReader { loop { match self.pages.try_next_page(&mut self.reader) { Ok(_) => break, - Err(Error::IoError(e, desc)) => return Err(Error::IoError(e, desc)), + Err(SymphoniaError::IoError(e)) => return Err(SymphoniaError::IoError(e)), Err(e) => { warn!("{}", e); } diff --git a/symphonia-format-ogg/src/page.rs b/symphonia-format-ogg/src/page.rs index ff811f3f..e824694c 100644 --- a/symphonia-format-ogg/src/page.rs +++ b/symphonia-format-ogg/src/page.rs @@ -6,7 +6,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use symphonia_core::checksum::Crc32; -use symphonia_core::errors::{decode_error, Error, Result}; +use symphonia_core::errors::{decode_error, SymphoniaError, Result}; use symphonia_core::io::{BufReader, Monitor, MonitorStream, ReadBytes, SeekBuffered}; use log::{debug, warn}; @@ -269,7 +269,7 @@ impl PageReader { loop { match self.try_next_page(reader) { Ok(_) => break, - Err(Error::IoError(e, desc)) => return Err(Error::IoError(e, desc)), + Err(SymphoniaError::IoError(e)) => return Err(SymphoniaError::IoError(e)), _ => (), } } @@ -290,7 +290,7 @@ impl PageReader { break; } } - Err(Error::IoError(e, desc)) => return Err(Error::IoError(e, desc)), + Err(SymphoniaError::IoError(e)) => return Err(SymphoniaError::IoError(e)), _ => (), } } diff --git a/symphonia-format-riff/src/common.rs b/symphonia-format-riff/src/common.rs index 2ac56aac..440522eb 100644 --- a/symphonia-format-riff/src/common.rs +++ b/symphonia-format-riff/src/common.rs @@ -12,7 +12,8 @@ use std::marker::PhantomData; use symphonia_core::audio::Channels; use symphonia_core::codecs::CodecParameters; use symphonia_core::codecs::CodecType; -use symphonia_core::errors::{decode_error, end_of_stream_error, Error, Result}; +use symphonia_core::errors::{decode_error, end_of_stream_error, Result}; +use symphonia_core::errors::SymphoniaError as Error; use symphonia_core::formats::prelude::*; use symphonia_core::io::{MediaSourceStream, ReadBytes}; diff --git a/symphonia-format-wav/src/chunks.rs b/symphonia-format-wav/src/chunks.rs index 3c5b695d..2d2b8129 100644 --- a/symphonia-format-wav/src/chunks.rs +++ b/symphonia-format-wav/src/chunks.rs @@ -17,7 +17,8 @@ use symphonia_core::codecs::{ CODEC_TYPE_PCM_F64LE, CODEC_TYPE_PCM_MULAW, CODEC_TYPE_PCM_S16LE, CODEC_TYPE_PCM_S24LE, CODEC_TYPE_PCM_S32LE, CODEC_TYPE_PCM_U8, }; -use symphonia_core::errors::{decode_error, unsupported_error, Error, Result}; +use symphonia_core::errors::{decode_error, unsupported_error, Result}; +use symphonia_core::errors::SymphoniaError as Error; use symphonia_core::io::ReadBytes; use symphonia_core::meta::Tag; use symphonia_metadata::riff; diff --git a/symphonia-play/src/main.rs b/symphonia-play/src/main.rs index 9655b3b3..40d7677b 100644 --- a/symphonia-play/src/main.rs +++ b/symphonia-play/src/main.rs @@ -18,7 +18,8 @@ use std::path::Path; use lazy_static::lazy_static; use symphonia::core::codecs::{DecoderOptions, FinalizeResult, CODEC_TYPE_NULL}; -use symphonia::core::errors::{Error, IoErrorKind, Result}; +use symphonia::core::errors::Result; +use symphonia::core::errors::SymphoniaError as Error; use symphonia::core::formats::{Cue, FormatOptions, FormatReader, SeekMode, SeekTo, Track}; use symphonia::core::io::{MediaSource, MediaSourceStream, ReadOnlySource}; use symphonia::core::meta::{ColorMode, MetadataOptions, MetadataRevision, Tag, Value, Visual}; @@ -402,7 +403,7 @@ fn first_supported_track(tracks: &[Track]) -> Option<&Track> { fn ignore_end_of_stream_error(result: Result<()>) -> Result<()> { match result { - Err(Error::IoError(IoErrorKind::UnexpectedEof, "end of stream")) => { + Err(Error::EndOfFile) => { // Do not treat "end of stream" as a fatal error. It's the currently only way a // format reader can indicate the media is complete. Ok(())