Skip to main content

qualia_core_db/net/qdnf/
errors.rs

1//! Stable QDNF outcomes. Hot paths return these Copy codes; they never allocate.
2
3use core::fmt;
4
5/// Typed protocol / runtime outcome. Display is diagnostic only; wire codes are
6/// the `as u16` discriminants below.
7#[repr(u16)]
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum QdnfError {
10    Truncated = 1,
11    Malformed = 2,
12    Unsupported = 3,
13    Capacity = 4,
14    WouldBlock = 5,
15    Closed = 6,
16    Unauthorized = 7,
17    Denied = 8,
18    Challenge = 9,
19    NeedsHuman = 10,
20    Incomplete = 11,
21    Ambiguous = 12,
22    Conflict = 13,
23    BudgetExhausted = 14,
24    Expired = 15,
25    Revoked = 16,
26    StaleGeneration = 17,
27    Replay = 18,
28    Downgrade = 19,
29    EntropyFailure = 20,
30    CryptoFailure = 21,
31    Overlap = 22,
32    HopLimit = 23,
33    NoRoute = 24,
34    PlatformUnsupported = 25,
35    Cancelled = 26,
36    DoubleRelease = 27,
37    ReservationUnchanged = 28,
38    UnknownProfile = 29,
39    CriticalExtension = 30,
40    Range = 31,
41}
42
43impl QdnfError {
44    /// Bytes consumed from the input when a decode fails. Zero means the caller
45    /// must not treat any prefix as a complete frame.
46    #[inline]
47    pub const fn consumed_on_failure(self) -> usize {
48        0
49    }
50
51    /// Output buffer is invalid after this failure.
52    #[inline]
53    pub const fn output_valid(self) -> bool {
54        false
55    }
56}
57
58impl fmt::Display for QdnfError {
59    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60        f.write_str(match self {
61            Self::Truncated => "truncated",
62            Self::Malformed => "malformed",
63            Self::Unsupported => "unsupported",
64            Self::Capacity => "capacity",
65            Self::WouldBlock => "would-block",
66            Self::Closed => "closed",
67            Self::Unauthorized => "unauthorized",
68            Self::Denied => "denied",
69            Self::Challenge => "challenge",
70            Self::NeedsHuman => "needs-human",
71            Self::Incomplete => "incomplete",
72            Self::Ambiguous => "ambiguous",
73            Self::Conflict => "conflict",
74            Self::BudgetExhausted => "budget-exhausted",
75            Self::Expired => "expired",
76            Self::Revoked => "revoked",
77            Self::StaleGeneration => "stale-generation",
78            Self::Replay => "replay",
79            Self::Downgrade => "downgrade",
80            Self::EntropyFailure => "entropy-failure",
81            Self::CryptoFailure => "crypto-failure",
82            Self::Overlap => "overlap",
83            Self::HopLimit => "hop-limit",
84            Self::NoRoute => "no-route",
85            Self::PlatformUnsupported => "platform-unsupported",
86            Self::Cancelled => "cancelled",
87            Self::DoubleRelease => "double-release",
88            Self::ReservationUnchanged => "reservation-unchanged",
89            Self::UnknownProfile => "unknown-profile",
90            Self::CriticalExtension => "critical-extension",
91            Self::Range => "range",
92        })
93    }
94}
95
96impl core::error::Error for QdnfError {}