Exception: Wasmtime::Trap

Inherits:
Error
  • Object
show all
Defined in:
lib/wasmtime/error.rb,
ext/src/ruby_api/trap.rs

Constant Summary collapse

STACK_OVERFLOW =
:stack_overflow
MEMORY_OUT_OF_BOUNDS =
:memory_out_of_bounds
HEAP_MISALIGNED =
:heap_misaligned
TABLE_OUT_OF_BOUNDS =
:table_out_of_bounds
INDIRECT_CALL_TO_NULL =
:indirect_call_to_null
BAD_SIGNATURE =
:bad_signature
INTEGER_OVERFLOW =
:integer_overflow
INTEGER_DIVISION_BY_ZERO =
:integer_division_by_zero
BAD_CONVERSION_TO_INTEGER =
:bad_conversion_to_integer
UNREACHABLE_CODE_REACHED =
:unreachable_code_reached
INTERRUPT =
:interrupt
ALWAYS_TRAP_ADAPTER =
:always_trap_adapter
OUT_OF_FUEL =
:out_of_fuel
UNKNOWN =
:unknown

Instance Method Summary collapse

Instance Method Details

#codeSymbol?

Returns the trap code as a Symbol, possibly nil if the trap did not origin from Wasm code. All possible trap codes are defined as constants on Wasmtime::Trap.

Returns:

  • (Symbol, nil)


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'ext/src/ruby_api/trap.rs', line 62

pub fn code(&self) -> Result<Option<Symbol>, Error> {
    match self.trap {
        wasmtime::Trap::StackOverflow => trap_const!(STACK_OVERFLOW),
        wasmtime::Trap::MemoryOutOfBounds => trap_const!(MEMORY_OUT_OF_BOUNDS),
        wasmtime::Trap::HeapMisaligned => trap_const!(HEAP_MISALIGNED),
        wasmtime::Trap::TableOutOfBounds => trap_const!(TABLE_OUT_OF_BOUNDS),
        wasmtime::Trap::IndirectCallToNull => trap_const!(INDIRECT_CALL_TO_NULL),
        wasmtime::Trap::BadSignature => trap_const!(BAD_SIGNATURE),
        wasmtime::Trap::IntegerOverflow => trap_const!(INTEGER_OVERFLOW),
        wasmtime::Trap::IntegerDivisionByZero => trap_const!(INTEGER_DIVISION_BY_ZERO),
        wasmtime::Trap::BadConversionToInteger => trap_const!(BAD_CONVERSION_TO_INTEGER),
        wasmtime::Trap::UnreachableCodeReached => trap_const!(UNREACHABLE_CODE_REACHED),
        wasmtime::Trap::Interrupt => trap_const!(INTERRUPT),
        wasmtime::Trap::AlwaysTrapAdapter => trap_const!(ALWAYS_TRAP_ADAPTER),
        wasmtime::Trap::OutOfFuel => trap_const!(OUT_OF_FUEL),
        // When adding a trap code here, define a matching constant on Wasmtime::Trap (in Ruby)
        _ => trap_const!(UNKNOWN),
    }
}

#messageString

Returns a textual description of the trap error, for example:

wasm trap: wasm `unreachable` instruction executed

Returns:

  • (String)


44
45
46
# File 'ext/src/ruby_api/trap.rs', line 44

pub fn message(&self) -> String {
    self.trap.to_string()
}

#wasm_backtrace_messageString?

Returns a textual representation of the Wasm backtrce, if it exists. For example:

error while executing at wasm backtrace:
    0:   0x1a - <unknown>!<wasm function 0>

Returns:

  • (String, nil)


54
55
56
# File 'ext/src/ruby_api/trap.rs', line 54

pub fn wasm_backtrace_message(&self) -> Option<String> {
    self.wasm_backtrace.as_ref().map(|bt| format!("{bt}"))
}