Skip to main content

codec_cbor/general/
error.rs

1// SPDX-FileCopyrightText: 2026 ReallyMe Technologies Limited
2//
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5use thiserror::Error;
6
7/// Schema-generated, fixed reasons for the compatibility error facade.
8pub use codec_proto::generated::proto::reallyme::codec::v1::CodecGeneralCborErrorReason as ErrorReason;
9
10/// General CBOR error with no input, offsets, strings, or dependency diagnostics.
11#[derive(Clone, Copy, Debug, Eq, Error, PartialEq)]
12#[error("general CBOR: {reason}")]
13pub struct CborError {
14    reason: ErrorReason,
15}
16
17impl CborError {
18    /// Construct a fixed typed error.
19    #[must_use]
20    pub const fn new(reason: ErrorReason) -> Self {
21        Self { reason }
22    }
23
24    /// Return the stable rejection reason.
25    #[must_use]
26    pub const fn reason(self) -> ErrorReason {
27        self.reason
28    }
29}
30
31pub(super) const fn error(reason: ErrorReason) -> CborError {
32    CborError::new(reason)
33}