Skip to main content

CodecError

Enum CodecError 

Source
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.

Fields

§available: usize
§

TruncatedPayload

The length prefix names a payload longer than what was supplied.

Fields

§declared: usize
§available: usize
§

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.

Fields

§declared: usize
§max: usize
§

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.

Fields

§declared: usize
§max: usize
§

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).

Fields

§kind: String
§detail: String
§

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).

Fields

§detail: String
§

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.

Fields

§code: String

Implementations§

Source§

impl CodecError

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for CodecError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for CodecError

Source§

impl Error for CodecError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<&CodecError> for WireErrorCode

Source§

fn from(err: &CodecError) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for CodecError

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CodecError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.