redoubt_codec_core/
error.rs

1// Copyright (c) 2025-2026 Federico Hoerth <memparanoid@gmail.com>
2// SPDX-License-Identifier: GPL-3.0-only
3// See LICENSE in the repository root for full license text.
4
5use alloc::string::String;
6
7use core::error;
8use core::fmt;
9
10use thiserror::Error;
11
12#[derive(Debug, Error, Eq, PartialEq)]
13pub enum RedoubtCodecBufferError {
14    #[error("CapacityExceeded")]
15    CapacityExceeded,
16}
17
18#[derive(Debug, Error, Eq, PartialEq)]
19pub enum DecodeBufferError {
20    #[error("OutOfBounds")]
21    OutOfBounds,
22}
23
24#[derive(Debug, Error, Eq, PartialEq)]
25pub enum EncodeError {
26    #[error("OverflowError: {0}")]
27    OverflowError(#[from] OverflowError),
28
29    #[error("RedoubtCodecBufferError: {0}")]
30    RedoubtCodecBufferError(#[from] RedoubtCodecBufferError),
31
32    /// Test-only error for simulating encode failures.
33    ///
34    /// Available only with `test-utils` feature enabled.
35    #[cfg(any(test, feature = "test-utils"))]
36    #[error("IntentionalEncodeError")]
37    IntentionalEncodeError,
38}
39
40#[derive(Debug, Error, Eq, PartialEq)]
41pub enum DecodeError {
42    #[error("DecodeBufferError: {0}")]
43    DecodeBufferError(#[from] DecodeBufferError),
44
45    #[error("PreconditionViolated")]
46    PreconditionViolated,
47
48    /// Test-only error for simulating decode failures.
49    ///
50    /// Available only with `test-utils` feature enabled.
51    #[cfg(any(test, feature = "test-utils"))]
52    #[error("IntentionalDecodeError")]
53    IntentionalDecodeError,
54}
55
56#[derive(Debug, PartialEq, Eq)]
57pub struct OverflowError {
58    pub reason: String,
59}
60
61impl fmt::Display for OverflowError {
62    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63        write!(f, "Overflow Error")
64    }
65}
66
67impl error::Error for OverflowError {}