5#ifndef WASMTIME_ERROR_HH
6#define WASMTIME_ERROR_HH
14#include <wasmtime/helpers.hh>
33 std::string message()
const {
36 auto ret = std::string(msg_bytes.
data, msg_bytes.
size);
43 std::optional<int32_t> i32_exit()
const {
70template <
typename T,
typename E = Error>
class [[nodiscard]]
Result {
71 std::variant<T, E> data;
81 explicit operator bool()
const {
return data.index() == 0; }
84 E &&
err() {
return std::get<E>(std::move(data)); }
86 const E &&
err()
const {
return std::get<E>(std::move(data)); }
89 T &&
ok() {
return std::get<T>(std::move(data)); }
91 const T &&
ok()
const {
return std::get<T>(std::move(data)); }
94 T &
ok_ref() {
return std::get<T>(data); }
96 const T &
ok_ref()
const {
return std::get<T>(data); }
99 E &
err_ref() {
return std::get<T>(data); }
101 const E &
err_ref()
const {
return std::get<T>(data); }
112 [[noreturn]]
void unwrap_failed() {
113 fprintf(stderr,
"error: %s\n", this->err().message().c_str());
Errors coming from Wasmtime.
Definition: error.hh:26
Fallible result type used for Wasmtime.
Definition: error.hh:70
const T && ok() const
Returns the success, if present, aborts if this is an error.
Definition: error.hh:91
E && err()
Returns the error, if present, aborts if this is not an error.
Definition: error.hh:84
T unwrap()
Returns the success, if present, aborts if this is an error.
Definition: error.hh:104
T && ok()
Returns the success, if present, aborts if this is an error.
Definition: error.hh:89
Result(T t)
Creates a Result from its successful value.
Definition: error.hh:75
const E && err() const
Returns the error, if present, aborts if this is not an error.
Definition: error.hh:86
const T & ok_ref() const
Returns the success, if present, aborts if this is an error.
Definition: error.hh:96
E & err_ref()
Returns the error, if present, aborts if this is not an error.
Definition: error.hh:99
const E & err_ref() const
Returns the error, if present, aborts if this is not an error.
Definition: error.hh:101
T & ok_ref()
Returns the success, if present, aborts if this is an error.
Definition: error.hh:94
Result(E e)
Creates a Result from an error value.
Definition: error.hh:77
An owned vector of FrameRef instances representing the WebAssembly call-stack on a trap.
Definition: trap.hh:66
Definition and accessors of wasmtime_error_t.
WASM_API_EXTERN void wasmtime_error_message(const wasmtime_error_t *error, wasm_name_t *message)
Returns the string description of this error.
WASM_API_EXTERN bool wasmtime_error_exit_status(const wasmtime_error_t *, int *status)
Attempts to extract a WASI-specific exit status from this error.
WASM_API_EXTERN wasmtime_error_t * wasmtime_error_new(const char *)
Creates a new error with the provided message.
std::ostream & operator<<(std::ostream &os, const Error &e)
Used to print an error.
Definition: error.hh:58
A list of bytes.
Definition: wasm.h:102
size_t size
Length of this vector.
Definition: wasm.h:102
wasm_byte_t * data
Pointer to the base of this vector.
Definition: wasm.h:102
Errors generated by Wasmtime.
void wasm_byte_vec_delete(wasm_byte_vec_t *)
Deletes a byte vector.