Skip to main content

adele_ring/
error.rs

1//! Crate-wide error types.
2//!
3//! These make the failure modes the refactor cares about *explicit*: range
4//! overflow during reconstruction, basis mismatches, and GPU bring-up failure.
5
6use thiserror::Error;
7
8/// A value could not be reconstructed within the provisioned basis range.
9///
10/// This is the headline fix from the refactor: exceeding the dynamic range is a
11/// **detected event**, never a silent aliasing modulo `M`.
12#[derive(Debug, Clone, PartialEq, Eq, Error)]
13pub enum RangeError {
14    #[error("rational reconstruction failed: have {have_bits} bits of range, need more")]
15    ReconstructionFailed { have_bits: u64, need_more: bool },
16    #[error("value of {value_bits} bits exceeds basis capacity of {capacity_bits} bits")]
17    CapacityExceeded { value_bits: u64, capacity_bits: u64 },
18}
19
20/// Problems constructing or combining a [`crate::basis::Basis`].
21#[derive(Debug, Clone, PartialEq, Eq, Error)]
22pub enum BasisError {
23    #[error("requested {requested_bits} bits but no further GPU-eligible primes are available")]
24    PrimesExhausted { requested_bits: u64 },
25    #[error("operands use different bases (len {a} vs {b})")]
26    Mismatch { a: usize, b: usize },
27}
28
29/// Operands carried mismatched bases/channels into an operation.
30#[derive(Debug, Clone, PartialEq, Eq, Error)]
31#[error("channel/basis mismatch: {0} vs {1}")]
32pub struct ChannelMismatch(pub usize, pub usize);
33
34/// GPU backend bring-up failure.
35#[derive(Debug, Error)]
36pub enum GpuError {
37    #[error("no compatible GPU adapter found")]
38    NoAdapter,
39    #[error("failed to acquire GPU device: {0}")]
40    Device(#[from] wgpu::RequestDeviceError),
41}