use jxr_core::JxrError;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum BatchErrorStage {
Preparation,
Decode,
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum BatchInfrastructureError {
#[error("JPEG XR batch contains {requested} inputs; configured maximum is {maximum}")]
TooManyInputs {
requested: usize,
maximum: usize,
},
#[error("JPEG XR batch output requires {requested} bytes; configured maximum is {maximum}")]
OutputAllocationTooLarge {
requested: u64,
maximum: u64,
},
#[error("failed to reserve {requested} bytes for {what}")]
HostAllocationFailed {
what: &'static str,
requested: usize,
},
#[error("failed to initialize JPEG XR batch workers: {message}")]
WorkerInitialization {
message: String,
},
#[error("JPEG XR {backend} batch does not support {layout:?} output layout")]
UnsupportedBatchLayout {
backend: &'static str,
layout: super::BatchLayout,
},
#[error("invalid JPEG XR CPU batch destination: {reason}")]
InvalidDestination {
reason: &'static str,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IndexedBatchError {
index: usize,
stage: BatchErrorStage,
source: JxrError,
}
impl IndexedBatchError {
pub(crate) const fn new(index: usize, stage: BatchErrorStage, source: JxrError) -> Self {
Self {
index,
stage,
source,
}
}
#[must_use]
pub const fn index(&self) -> usize {
self.index
}
#[must_use]
pub const fn stage(&self) -> BatchErrorStage {
self.stage
}
#[must_use]
pub const fn source(&self) -> &JxrError {
&self.source
}
}