Skip to main content

j2k_ml/
error.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3/// Failure while decoding or staging a codec batch into Burn.
4#[derive(Debug, thiserror::Error)]
5pub enum BurnDecodeError {
6    /// The codec could not allocate or schedule the requested batch.
7    #[error("JPEG 2000 batch infrastructure failed: {0}")]
8    Infrastructure(#[from] j2k::BatchInfrastructureError),
9    /// The selected Burn backend cannot represent the codec's exact integer type.
10    #[error("Burn backend does not support exact codec dtype {dtype:?}")]
11    UnsupportedDType {
12        /// Required Burn storage dtype.
13        dtype: burn_core::tensor::DType,
14    },
15    /// Codec group metadata and the returned native sample owner disagreed.
16    #[error("codec batch sample owner did not match its declared sample type")]
17    SampleTypeMismatch,
18    /// Tensor shape arithmetic overflowed the host index type.
19    #[error("Burn tensor shape overflow")]
20    SizeOverflow,
21    /// A newer codec contract cannot be represented by this adapter version.
22    #[error("unsupported codec batch layout or sample type")]
23    UnsupportedCodecContract,
24    /// CUDA rejected or could not complete one homogeneous codec group.
25    #[cfg(feature = "cuda")]
26    #[error(transparent)]
27    Cuda(#[from] j2k_cuda::CudaBatchError),
28    /// Metal rejected or could not complete one homogeneous codec group.
29    #[cfg(feature = "metal")]
30    #[error(transparent)]
31    Metal(#[from] j2k_metal::Error),
32    /// A framework allocation, readback, or upload boundary failed.
33    #[error("{backend} tensor transfer failed: {message}")]
34    AcceleratorInterop {
35        /// Accelerator runtime at the failing boundary.
36        backend: &'static str,
37        /// Actionable transfer, bounds, or platform detail.
38        message: String,
39    },
40}