pub enum CodecError {
TruncatedLengthPrefix {
available: usize,
},
TruncatedPayload {
declared: usize,
available: usize,
},
FrameTooLarge {
declared: usize,
max: usize,
},
U32PrefixLimitExceeded {
declared: usize,
max: usize,
},
InvalidJson(String),
MissingKind,
UnknownFrameKind(String),
InvalidFields {
kind: String,
detail: String,
},
InconsistentErrorScope {
detail: String,
},
FallbackFrameNotEncodable {
code: String,
},
}Expand description
A codec failure, distinguishing every frame-level case this crate can
identify. Every variant maps onto the wire error taxonomy —
crate::error::WireErrorCode::MalformedFrame,
crate::error::WireErrorCode::Internal, or
crate::error::WireErrorCode::FrameTooLarge — canonically via
wire_code (and the From<&CodecError> impl), so
servers need no hand-maintained mapping; this crate keeps the
finer-grained variant so a caller (including a test) can assert the
specific failure rather than only “decoding failed”.
Variants§
TruncatedLengthPrefix
Fewer than LENGTH_PREFIX_BYTES bytes were supplied — the 4-byte
length prefix itself is truncated.
TruncatedPayload
The length prefix names a payload longer than what was supplied.
FrameTooLarge
The declared frame length exceeds the configured maximum
(payload-only; the 4-byte prefix never counts against it). max
is always the configured bound that was exceeded.
U32PrefixLimitExceeded
The serialized payload exceeds the 4-byte length prefix’s inherent
u32::MAX byte capacity. Distinct from FrameTooLarge: this arm
can only fire when the configured maximum is at least the payload
length (otherwise FrameTooLarge fires first), so the configured
maximum was NOT the binding limit — the prefix capacity was, and
the error names it.
InvalidJson(String)
Decode side: the payload bytes are not valid JSON at all. Encode
side: the frame failed to serialize (only reachable for opaque
payloads that cannot be represented, e.g. a map with non-string
keys smuggled into response.result).
MissingKind
The payload is valid JSON but not a JSON object, or has no "kind"
string field (absent or not a string).
UnknownFrameKind(String)
The "kind" field names a value outside the closed
crate::frame::FRAME_KINDS set.
InvalidFields
The frame’s "kind" was recognized but a field required by that
frame kind’s shape is missing, has the wrong type, or is unknown to
the closed grammar (strict field rejection — see the crate
documentation’s “Strict field rejection” section). Encode side: an
operation id field carries the empty string, which the wire grammar
forbids (crate::frame::OperationId).
InconsistentErrorScope
An error frame whose operation-id presence contradicts its code’s
terminal scope (ADR-137, “Operation correlation”): a
connection-terminal code carries no operation id, and a
request-terminal code echoes the one it terminates. Enforced at
decode — inside crate::frame::Frame’s serde visitor, so BOTH
the codec’s decode_payload and a direct
serde_json::from_str::<Frame> reject it (the codec re-classifies
the visitor’s message into this typed variant) — AND at encode
(encode_frame_with_max).
FallbackFrameNotEncodable
Encode side: the frame is a decoded unknown-code fallback — a
crate::frame::Frame::Error carrying a Some
unrecognized_code, which only a decode path sets when the wire
carried a code outside the closed set. Re-encoding one would emit
the fallback code (internal) and silently discard the newer code
the peer sent, so the encode path rejects this local relay attempt;
the connection remains healthy, but this relay cannot re-encode the
decoded frame. If a relay must pass unknown codes through, it has to
operate on the raw frame bytes, not on a decoded-and-re-encoded frame.
Implementations§
Source§impl CodecError
impl CodecError
Sourcepub const fn wire_code(&self) -> WireErrorCode
pub const fn wire_code(&self) -> WireErrorCode
The wire error code this failure maps to under ADR-137’s taxonomy:
FrameTooLarge and
U32PrefixLimitExceeded — the size
failures — map to WireErrorCode::FrameTooLarge. A decoded fallback
that this local relay cannot re-encode maps to
WireErrorCode::Internal; the connection is healthy and only the
relay attempt failed. Every other variant maps to
WireErrorCode::MalformedFrame. This is the canonical
codec→wire-error mapping: servers should use it (or the
From<&CodecError> impl) rather than hand-maintain their own.
Trait Implementations§
Source§impl Debug for CodecError
impl Debug for CodecError
Source§impl Display for CodecError
impl Display for CodecError
impl Eq for CodecError
Source§impl Error for CodecError
impl Error for CodecError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()