#[non_exhaustive]#[repr(u8)]pub enum ErrorCode {
Show 45 variants
UnexpectedEnd = 0,
ExpectedBrace = 1,
ExpectedBracket = 2,
ExpectedQuote = 3,
ExpectedColon = 4,
ExpectedComma = 5,
ExpectedTrue = 6,
ExpectedFalse = 7,
ExpectedNull = 8,
UnexpectedCharacter = 9,
TrailingContent = 10,
ExceededMaxDepth = 11,
DocumentTooLarge = 12,
InvalidHeader = 13,
InvalidPadding = 14,
UnsupportedFeature = 15,
UnsupportedKeyType = 16,
ExpectedObject = 17,
ExpectedArray = 18,
ExpectedString = 19,
ExpectedBool = 20,
ExpectedInteger = 21,
ExpectedBytes = 22,
ElementTypeMismatch = 23,
ExpectedComplex = 24,
ExpectedMatrix = 25,
ExpectedVariant = 26,
ExpectedTag = 27,
NumberOutOfRange = 28,
InvalidNumber = 29,
ExpectedNumber = 30,
InvalidEscape = 31,
InvalidSurrogate = 32,
InvalidUtf8 = 33,
ControlCharacterInString = 34,
EscapeInBorrowedString = 35,
ArrayLengthMismatch = 36,
ExpectedSingleChar = 37,
UnknownKey = 38,
UnknownVariant = 39,
MissingKey = 40,
InvalidMatrixShape = 41,
InvalidMatrixLayout = 42,
InvalidPointer = 43,
NoSuchValue = 44,
}Expand description
What went wrong. One byte, so error propagation stays cheap.
One set covers both formats, and a code does not say which one produced it.
A few belong to one format by construction, ExpectedBrace
to JSON and InvalidHeader to BEVE, but most of the
set is shared and which ones are is not a promise. The entry point is what
names the format, so code that needs to report which codec failed should
record it where it chose the codec.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
UnexpectedEnd = 0
ExpectedBrace = 1
ExpectedBracket = 2
ExpectedQuote = 3
ExpectedColon = 4
ExpectedComma = 5
ExpectedTrue = 6
ExpectedFalse = 7
ExpectedNull = 8
UnexpectedCharacter = 9
TrailingContent = 10
ExceededMaxDepth = 11
DocumentTooLarge = 12
A streaming reader would have had to buffer more than its configured
limit to hold one value. See Documents::max_value.
InvalidHeader = 13
A header byte named a type, width, or extension this crate cannot read, or was the delimiter where a value belongs. Also an aligned complex array whose inner array is not the one its class allows: not aligned, of another element type, or holding an odd number of components.
InvalidPadding = 14
Padding broke the specification’s rule for it. A packed-boolean array
set a bit past its last element, where the unused high bits of the
final byte must be zero, so each set one would be another encoding of
the same array. Or an aligned typed array stated a padding length of
its element’s width or more, where the specification allows only
0..width; in an aligned complex array the element is one component.
The header is well formed; what follows it is not.
UnsupportedFeature = 15
A well-formed BEVE construct with nowhere to go: a 128-bit float, an extension beyond the four the specification defines, or, when transcoding, the deprecated type tag.
UnsupportedKeyType = 16
An object’s keys were of a kind the destination cannot take, such as integer keys for a struct.
ExpectedObject = 17
ExpectedArray = 18
ExpectedString = 19
ExpectedBool = 20
ExpectedInteger = 21
ExpectedBytes = 22
An array of one-byte elements was expected, for a borrowed &[u8].
ElementTypeMismatch = 23
A typed array’s stored element type was not the one a bulk read needs.
Reading is otherwise lenient about width: an i64 field takes a stored
i16 and a f64 takes a stored f32, because the value fits. That
leniency is a conversion done one element at a time, so the paths that
exist to move a whole block at once cannot offer it, and say this
instead of quietly becoming the slow path. See
read_beve_array_into.
ExpectedComplex = 24
A Complex was expected but the value was neither a
complex extension nor a two-element array.
ExpectedMatrix = 25
A BEVE value was read as a Matrix but was neither a
matrix extension nor an object. BEVE only: the JSON reader wants an
object like any other and says ExpectedBrace.
ExpectedVariant = 26
An enum was neither a variant name nor an object holding exactly one member that names one.
The two forms are the whole encoding: a variant carrying nothing is its name, and a variant carrying a value is that name used as the single key of an object. Anything else, an object with no members or with two, a number, an array, is not a variant at all.
ExpectedTag = 27
An internally tagged enum’s object did not begin with its tag.
An internally tagged enum, declared
tagged_enum!(.. as tag ".."), reads in one
pass, so the member deciding which variant this is has to arrive before
the members whose meaning it decides. An object whose first member is
some other key is refused here rather than searched: finding a later tag
would mean holding the object somewhere or walking it twice, and this
crate does neither.
The same code covers an object with no members at all, and a tag whose value is not a string. Which of the three it was is not distinguished, because distinguishing them is the search being refused. The reported position is the object’s first member, or the object itself when it has none.
A tag that is first and names nothing is
UnknownVariant: the tag was found, and its
value is not a variant.
NumberOutOfRange = 28
InvalidNumber = 29
ExpectedNumber = 30
InvalidEscape = 31
InvalidSurrogate = 32
InvalidUtf8 = 33
ControlCharacterInString = 34
EscapeInBorrowedString = 35
A borrowed &str was requested but the JSON string contained escapes,
so no subslice of the input can represent it.
ArrayLengthMismatch = 36
A fixed-size target ([T; N], a tuple) did not match the JSON length.
ExpectedSingleChar = 37
A char was requested but the string was not exactly one scalar value.
UnknownKey = 38
An object held a key that no field of the destination claims, under the
default Options::ERROR_ON_UNKNOWN_KEYS.
Read with SkipUnknown to step over it instead.
The reported position is the key itself, so the message names what was
not recognized. That holds for a struct declared with
object! and for the readers written by hand, which
wind back to the key before refusing: a map callback runs after the
colon, and reporting from there would name the value instead. See
json::Parser::read_map_located.
The name is not carried, an ErrorCode being one byte and the name
being a run of the document rather than a constant of the destination.
Error::key_in reads it back out of the
document, which is where it still is.
UnknownVariant = 39
An enum’s tag named no variant the destination declares.
Unlike UnknownKey this is refused under every
policy, SkipUnknown included. A member with
nowhere to go can be stepped over and the rest of the object still
read; a variant with nowhere to go leaves the value itself undecided.
MissingKey = 40
An object left out a field that had to be there: one marked
#[required] in the declaration, or any of them under
Options::ERROR_ON_MISSING_KEYS.
Neither is on by default: absence otherwise means the destination keeps
what it already held. Mark the members a document has to carry, or read
with RequireKeys to insist on every one.
Which field is missing is not carried, an ErrorCode being one byte.
The reported position is where the object began, its opening brace in
JSON and its header byte in BEVE, so the message names the incomplete
object rather than the byte that closed it. Matrix
reads by hand and reports the same way.
InvalidMatrixShape = 41
A matrix held a different number of elements than its extents describe.
InvalidMatrixLayout = 42
A matrix named a storage order that is not one of the two defined. It says which index varies fastest, so reading it wrongly would transpose the data without any length being wrong, which is why it is refused rather than guessed at.
InvalidPointer = 43
A pointer was not valid RFC 6901
syntax: it did not start with /, or a token held a stray ~, or an
array index was not a decimal number without leading zeros. The - the
RFC defines for the position after the last element is well formed and
so is NoSuchValue instead.
NoSuchValue = 44
A pointer was well formed but named a member or element the document does not hold.
Implementations§
Trait Implementations§
impl Copy for ErrorCode
impl Eq for ErrorCode
Source§impl Error for ErrorCode
A code stands on its own wherever there is no input to locate it in, which
is why Matrix::new hands one back rather than an
Error: a value assembled in memory has no byte offset to report.
impl Error for ErrorCode
A code stands on its own wherever there is no input to locate it in, which
is why Matrix::new hands one back rather than an
Error: a value assembled in memory has no byte offset to report.
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()