pub enum DecodeError {
Truncated,
BadMagic,
BadVersion(u8),
BadTag,
BadGeometry,
BadSpan,
}Expand description
Why a byte buffer could not be decoded into a Frame.
Variants§
Truncated
Ran out of bytes mid-field.
BadMagic
First two bytes are not the wire magic.
BadVersion(u8)
Unsupported format version.
BadTag
A tag/kind byte held a value outside its defined set.
BadGeometry
The frame’s own declared geometry is one no terminal can have: fewer than
MIN_COLUMNS columns, or no rows at all (#663).
Distinct from BadSpan, and the distinction is the direction of
the comparison rather than a shade of severity. BadSpan means a part of the
frame does not fit the geometry the header declares; this means the header itself
declares a geometry the engine defines as impossible and clamps away at every entry
point (Term::with_scrollback and Term::resize widen
cols to MIN_COLUMNS and rows to 1). Nothing this crate encodes can carry it,
so it is malformed input by the same rule BadSpan applies one level in.
The floor imports no policy: xterm.js clamps to the same pair for the same reason
(MINIMUM_COLS = 2, “Less than 2 can mess with wide chars”, and
MINIMUM_ROWS = 1). There is deliberately no ceiling error — cols/rows are
u16 on the wire and MAX_COLUMNS is u16::MAX for exactly
that reason, so the upper end is bounded by the field and needs no check.
This variant is what BadSpan’s doc-comment deferred to “the next release that is
breaking anyway” — #663 changes what decode accepts, so the version that carries
it is that release, and the marginal cost of the enum growing is paid there rather
than on its own. Measured at the time: no exhaustive match on DecodeError exists
in this workspace, justerm-wasm-decode formats the variant with {:?} (so the
name reaches JS unaided, #662), and penterm holds no reference to the type.
BadSpan
A part of the frame does not fit the geometry the frame itself declares: a span
whose left is past its right (which would underflow the cell count), a span
reaching past cols or sitting past rows, a sparse group entry keyed outside
its own span, or a scroll region whose bottom is past the last row (#582).
One rule, one error: a coordinate describing a cell the frame says does not exist is malformed input, and the consumer must not be handed it.
A dedicated BadScroll was considered and not taken, and the trade is worth
stating honestly rather than as a slogan. Against it: this enum is pub and not
#[non_exhaustive], so a new variant is a breaking change for any downstream
exhaustive match — of which there are, measured, none in this workspace; the
cost is borne only by an external matcher nobody has seen. For it: this variant is
now the whole diagnostic for six distinct malformations, and the JS side has no
more to work with (justerm-wasm-decode formats the variant name into the thrown
Error’s message, #662). The distinction is real but belongs to the next
release that is breaking anyway — a version bump spent on a diagnostic label, on
a crate published in lockstep with an npm package, is the more expensive half of
this trade today.
That condition arrived, and only for the case it names (#663).
BadGeometry split off because #663 changes what decode
accepts, so its release is the breaking one this paragraph was waiting for. It is
not a precedent for splitting the six below: the new variant answers a comparison
pointing the other way (the header against the engine, not a part against the
header), whereas BadScroll would still be one of these six re-labelled. The trade
above is unchanged for them and they stay merged.
Trait Implementations§
Source§impl Clone for DecodeError
impl Clone for DecodeError
Source§fn clone(&self) -> DecodeError
fn clone(&self) -> DecodeError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more