5#ifndef WASMTIME_ERROR_HH
6#define WASMTIME_ERROR_HH
30 std::unique_ptr<wasmtime_error_t, deleter> ptr;
45 auto ret = std::string(msg_bytes.
data, msg_bytes.
size);
82template <
typename T,
typename E = Error>
class [[nodiscard]]
Result {
83 std::variant<T, E> data;
93 explicit operator bool()
const {
return data.index() == 0; }
96 E &&
err() {
return std::get<E>(std::move(data)); }
98 const E &&
err()
const {
return std::get<E>(std::move(data)); }
101 T &&
ok() {
return std::get<T>(std::move(data)); }
103 const T &&
ok()
const {
return std::get<T>(std::move(data)); }
114 [[noreturn]]
void unwrap_failed() {
115 fprintf(stderr,
"error: %s\n", this->err().message().c_str());
Errors coming from Wasmtime.
Definition: error.hh:25
Error(const std::string &s)
Creates an error with the provided message.
Definition: error.hh:39
Error(wasmtime_error_t *error)
Creates an error from the raw C API representation.
Definition: error.hh:36
wasmtime_error_t * release()
Release ownership of this error, acquiring the underlying C raw pointer.
Definition: error.hh:66
Trace trace() const
Definition: trap.hh:97
std::optional< int32_t > i32_exit() const
Definition: error.hh:52
std::string message() const
Returns the error message associated with this error.
Definition: error.hh:42
Fallible result type used for Wasmtime.
Definition: error.hh:82
const T && ok() const
Returns the success, if present, aborts if this is an error.
Definition: error.hh:103
E && err()
Returns the error, if present, aborts if this is not an error.
Definition: error.hh:96
T unwrap()
Returns the success, if present, aborts if this is an error.
Definition: error.hh:106
T && ok()
Returns the success, if present, aborts if this is an error.
Definition: error.hh:101
Result(T t)
Creates a Result from its successful value.
Definition: error.hh:87
const E && err() const
Returns the error, if present, aborts if this is not an error.
Definition: error.hh:98
Result(E e)
Creates a Result from an error value.
Definition: error.hh:89
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.
void wasmtime_error_message(const wasmtime_error_t *error, wasm_name_t *message)
Returns the string description of this error.
void wasmtime_error_delete(wasmtime_error_t *error)
Deletes an error.
wasmtime_error_t * wasmtime_error_new(const char *)
Creates a new error with the provided message.
bool wasmtime_error_exit_status(const wasmtime_error_t *, int *status)
Attempts to extract a WASI-specific exit status from this error.
std::ostream & operator<<(std::ostream &os, const Error &e)
Used to print an error.
Definition: error.hh:70
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.