Skip to main content

ErrorKind

Enum ErrorKind 

Source
#[non_exhaustive]
pub enum ErrorKind {
Show 22 variants ArithOverflow, DivByZero, ShiftOutOfRange, InvalidConversion, InvalidChar, NegativeExponent, TypeError, NullReference, IndexOutOfBounds, KeyNotFound, UndefinedProperty, StackOverflow, OutOfMemory, OutOfFuel, InvalidStrIndex, Unreachable, InvalidCoroState, CannotSuspend, NoScheduler, CloseIgnored, ArgumentError, NoMatch,
}
Expand description

A runtime error kind with its stable code.

Codes E0001–E0099 are defined by specs/OPS.md §6 for arithmetic and conversions, E0100–E0199 by LSB for the other instructions, and E0200–E0299 by HIR for its own forms (specs/HIR.md §8.10). Every execution tier raises the same kind for the same fault. Inst::ErrCode reads the numeric code back from a caught error value, and Inst::Raise raises any catchable kind from bytecode (how a code generator raises HIR’s NoMatch).

§Examples

use bytecode_lang::ErrorKind;

assert_eq!(ErrorKind::DivByZero.code(), 2);
assert_eq!(ErrorKind::DivByZero.to_string(), "E0002 DivByZero");
assert_eq!(ErrorKind::from_code(102), Some(ErrorKind::IndexOutOfBounds));
assert!(!ErrorKind::OutOfFuel.is_catchable());

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

ArithOverflow

E0001: an integer result does not fit under overflow = error.

§

DivByZero

E0002: integer division by zero under div_zero = error.

§

ShiftOutOfRange

E0003: a shift amount out of range under shift = error.

§

InvalidConversion

E0004: NaN or an out-of-range float converted under float_to_int = error.

§

InvalidChar

E0005: char_from_u32 on a value that is not a Unicode scalar value.

§

NegativeExponent

E0006: integer pow with a negative exponent under any overflow policy but promote (OPS v2).

§

TypeError

E0100: a dynamic operation on kinds it does not support, a failed cast or from_dyn, or an argument of a dynamic call that does not convert to its parameter’s type.

§

NullReference

E0101: a heap instruction on a nil reference.

§

IndexOutOfBounds

E0102: an array, string, or length operand out of range.

§

KeyNotFound

E0103: map_get (or dget_index on a map) of an absent key.

§

UndefinedProperty

E0104: get_prop/set_prop of a name the object does not have.

§

StackOverflow

E0105: the call depth limit was reached.

§

OutOfMemory

E0106: an allocation failed. Always a trap.

§

OutOfFuel

E0107: the run’s fuel budget is spent. Always a trap.

§

InvalidStrIndex

E0108: a UTF-8 str_slice boundary inside a character.

§

Unreachable

E0109: unreachable was executed. Always a trap.

§

InvalidCoroState

E0110: a coroutine operation in a state that does not allow it: resuming one that is running, returned, or failed (a coroutine resuming itself included), or coro_result before it returned.

§

CannotSuspend

E0111: yield or await with no coroutine to suspend, or with a host frame between the instruction and its coroutine.

§

NoScheduler

E0112: spawn in a module with no spawn hook bound.

§

CloseIgnored

E0113: a coroutine being closed yielded instead of finishing (Python’s “generator ignored GeneratorExit”).

§

ArgumentError

E0114: a dynamic call’s arguments do not bind to the callee’s parameters: too many or too few, an unknown or repeated name, a positional argument after a named one (see ParamList::bind).

§

NoMatch

E0200: a match none of whose arms matches (HIR v3 §8.10; Mox’s UnhandledMatchError). No instruction raises it by itself: code generators raise it with Inst::Raise, the scrutinee as payload.

Implementations§

Source§

impl ErrorKind

Source

pub const ALL: &'static [ErrorKind]

Every kind, in code order.

Source

pub const fn code(self) -> u32

The stable numeric code (2 for E0002).

§Examples
use bytecode_lang::ErrorKind;

assert_eq!(ErrorKind::TypeError.code(), 100);
Source

pub fn from_code(code: u32) -> Option<Self>

The kind with this numeric code, or None.

§Examples
use bytecode_lang::ErrorKind;

assert_eq!(ErrorKind::from_code(1), Some(ErrorKind::ArithOverflow));
assert_eq!(ErrorKind::from_code(0), None);
Source

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

The kind’s name, as in OPS and LSB.

§Examples
use bytecode_lang::ErrorKind;

assert_eq!(ErrorKind::KeyNotFound.name(), "KeyNotFound");
Source

pub const fn is_catchable(self) -> bool

Whether a try region can catch this kind. Resource exhaustion and unreachable always abort the run; every other kind is raised as an error (or aborts, if the instruction’s policy says trap).

§Examples
use bytecode_lang::ErrorKind;

assert!(ErrorKind::KeyNotFound.is_catchable());
assert!(!ErrorKind::Unreachable.is_catchable());

Trait Implementations§

Source§

impl Clone for ErrorKind

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 ErrorKind

Source§

impl Debug for ErrorKind

Source§

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

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

impl Display for ErrorKind

E0002 DivByZero.

Source§

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

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

impl Eq for ErrorKind

Source§

impl Hash for ErrorKind

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 Ord for ErrorKind

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for ErrorKind

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 PartialOrd for ErrorKind

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for ErrorKind

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.