use crate::EncodeError;
use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum FramedEncodeError {
#[error("invalid framed encoder configuration: {0}")]
Config(#[from] crate::ConfigError),
#[error("framing output is pending")]
OutputPending,
#[error("a framed session was abandoned; recover the owner")]
AbandonedSession,
#[error("a framed resource was abandoned")]
AbandonedResource,
#[error("invalid framed encoder state")]
InvalidState,
#[error("framed output destination is too small")]
OutputTooSmall,
#[error("framing allocation failed")]
AllocationFailed,
#[error("{scope} input size mismatch: expected {expected}, actual {actual}")]
InputSizeMismatch {
scope: &'static str,
expected: u64,
actual: u64,
},
#[error("invalid framing operation: {0}")]
Invalid(&'static str),
#[error("framing {kind} limit exceeded (limit {limit})")]
Limit {
kind: &'static str,
limit: u64,
},
#[error("framing size or offset overflow")]
Overflow,
#[error("resource encoding failed: {0}")]
Encode(#[from] EncodeError),
#[error("container output failed: {0}")]
#[cfg(not(feature = "no_std"))]
Io(#[from] std::io::Error),
}
#[cfg(not(feature = "no_std"))]
impl From<FramingError> for std::io::Error {
fn from(error: FramingError) -> Self {
match error {
FramingError::Io(error) => error,
other => Self::other(other),
}
}
}
#[derive(Debug)]
#[cfg(not(feature = "no_std"))]
pub struct FramingFinishError<T> {
pub writer: T,
pub error: FramingError,
}
pub type FramingError = FramedEncodeError;
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct FramedEncodeLocation {
pub resource_index: Option<u64>,
pub item_index: Option<usize>,
pub resource_input_offset: Option<u64>,
pub wire_offset: u64,
}
#[derive(Debug, Error)]
#[error("{error}")]
pub struct FramedEncodeFailure {
#[source]
pub error: FramedEncodeError,
pub consumed: usize,
pub produced: usize,
pub location: FramedEncodeLocation,
}
impl FramedEncodeFailure {
pub fn into_error(self) -> FramedEncodeError {
self.error
}
}