pub enum WireError {
Truncated {
at: usize,
needed: usize,
available: usize,
},
ImpossibleLength {
at: usize,
claimed: usize,
available: usize,
},
NotUtf8 {
at: usize,
},
OutOfRange {
at: usize,
expected: String,
},
Discarded {
at: usize,
expected: String,
found: String,
},
WrongFraming {
at: usize,
expected: String,
found: String,
fits: Option<&'static str>,
},
}Expand description
Why a read failed, or a write refused.
Every variant names what was expected and where. A reader that
returned a zero for a truncated stream would hand the caller a value
that was never sent; a writer that narrowed a value it cannot carry
would send one nobody wrote. OutOfRange is the variant both use —
at is the offset read from on the way in and the offset the value
would have gone to on the way out.
Variants§
Truncated
The stream ended before the value did.
Fields
ImpossibleLength
A length field claims more than the stream holds.
Separate from Truncated: a length that cannot be true is a
malformed stream, not a short one, and allocating for it is how a
reader turns a bad message into an out-of-memory.
Fields
NotUtf8
A string held bytes that are not UTF-8.
OutOfRange
A value outside what its type admits.
Discarded
A value the receiving type cannot hold, under a position whose
try_construct is DISCARD.
DDS-XTypes 1.3 §7.2.2.7 and §7.2.4.1: “the default behavior is to discard the O2 object to avoid misinterpretation.” §7.2.3 says the sample “can be safely ignored (filtered out) by the receiver”.
Kept apart from every other variant on purpose, and the
distinction is measured. Cyclone’s path is the clearest witness:
dds_stream_normalize fails inside ddsi_serdata_from_ser,
which returns NULL, and delivery ends at
remote_on_delivery_failure_fastpath — the sample never becomes
a sample. A discarded sample is an absence, not an error. The
stream is well formed and the next sample may well fit; every
other variant here says the stream is wrong. The reflective
column spells it ProbeError::Discarded, the C column
ZDW_DISCARDED and the Python column Discarded.
Fields
WrongFraming
The stream is well formed and framed the way another implementation frames it, not the way this reader is configured.
Separate from Self::OutOfRange on purpose. A reader given the
wrong dialect and a reader given a corrupt stream both stop, and
only one of them is fixed by changing a flag. Telling a user
“expected a four-byte parameter length” when the answer is
--dialect fastdds costs an afternoon; naming the form the bytes
do fit costs nothing.
Fields
Implementations§
Source§impl WireError
impl WireError
Sourcepub fn refused(at: usize, expected: &str) -> Self
pub fn refused(at: usize, expected: &str) -> Self
A refusal raised from outside the runtime.
The runtime owns the wire and the generated code owns the type,
and some refusals are the type’s: a member the stream says is
absent where the generated field cannot hold an absence, a value
that names no enumerator. runtime/c already has
zdw_reader_refuse for exactly this; the Rust column had no way
to say it and read on instead, which puts every following member
at the wrong offset and reports success.
Sourcepub const fn is_discarded(&self) -> bool
pub const fn is_discarded(&self) -> bool
Whether this is the absence WireError::Discarded describes
rather than a statement that the stream is malformed.
The one question a subscriber has to be able to ask: a discarded sample is dropped and the next one read, a malformed stream is reported. §7.2.4.1 against §7.2.3.
Trait Implementations§
impl Eq for WireError
Source§impl Error for WireError
impl Error for WireError
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()