use std::fmt::{Debug, Display};
use derive_more::Display;
use mediasan_common::error::ReportableError;
use mediasan_common::parse::FourCC;
use mediasan_common::{Result, ResultExt};
#[derive(Clone, Debug, thiserror::Error)]
pub enum ParseError {
#[error("Invalid chunk layout")]
InvalidChunkLayout,
#[error("Invalid input")]
InvalidInput,
#[error("Invalid VP8L prefix code")]
InvalidVp8lPrefixCode,
#[error("Missing required `{_0}` chunk")]
MissingRequiredChunk(FourCC),
#[error("TruncatedChunk")]
TruncatedChunk,
#[error("Unsupported chunk `{_0}`")]
UnsupportedChunk(FourCC),
#[error("Unsupported VP8L version `{_0}`")]
UnsupportedVp8lVersion(u8),
}
pub(crate) trait ParseResultExt: ResultExt + Sized {
fn while_parsing_chunk(self, chunk_type: FourCC) -> Self {
self.attach_printable(WhileParsingChunk(chunk_type))
}
fn while_parsing_field<T>(self, chunk_type: FourCC, field_name: T) -> Self
where
T: Display + Debug + Send + Sync + 'static,
{
self.attach_printable(WhileParsingField(chunk_type, field_name))
}
}
#[derive(Clone, Copy, Debug, Display)]
#[display(fmt = "multiple `{}` chunks", _0)]
pub(crate) struct MultipleChunks(pub(crate) FourCC);
#[derive(Clone, Copy, Debug, Display)]
#[display(fmt = "expected `{}` chunk", _0)]
pub(crate) struct ExpectedChunk(pub(crate) FourCC);
#[derive(Clone, Copy, Debug, Display)]
#[display(fmt = "while parsing `{}` chunk", _0)]
pub(crate) struct WhileParsingChunk(pub(crate) FourCC);
#[derive(Clone, Copy, Debug, Display)]
#[display(fmt = "while parsing `{}` chunk field `{}`", _0, _1)]
pub(crate) struct WhileParsingField<T>(pub(crate) FourCC, pub(crate) T);
impl ReportableError for ParseError {
#[cfg(feature = "error-detail")]
type Stack = mediasan_common::error::ReportStack;
#[cfg(not(feature = "error-detail"))]
type Stack = mediasan_common::error::NullReportStack;
}
impl<T> ParseResultExt for Result<T, ParseError> {}