Skip to main content

ErrorCode

Enum ErrorCode 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future 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

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§

Source§

impl ErrorCode

Source

pub const fn message(self) -> &'static str

A short, stable, human readable description.

Trait Implementations§

Source§

impl Clone for ErrorCode

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ErrorCode

Source§

impl Debug for ErrorCode

Source§

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

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

impl Display for ErrorCode

Source§

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

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

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.

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 Hash for ErrorCode

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ErrorCode

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 ErrorCode

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.