5#ifndef WASMTIME_ERROR_HH
6#define WASMTIME_ERROR_HH
29 std::unique_ptr<wasmtime_error_t, deleter> ptr;
44 auto ret = std::string(msg_bytes.
data, msg_bytes.
size);
83template <
typename T,
typename E = Error>
class [[nodiscard]]
Result {
84 std::variant<T, E> data;
94 explicit operator bool()
const {
return data.index() == 0; }
97 E &&
err() {
return std::get<E>(std::move(data)); }
99 const E &&
err()
const {
return std::get<E>(std::move(data)); }
102 T &&
ok() {
return std::get<T>(std::move(data)); }
104 const T &&
ok()
const {
return std::get<T>(std::move(data)); }
115 [[noreturn]]
void unwrap_failed() {
116 fprintf(stderr,
"error: %s\n", this->err().message().c_str());
Errors coming from Wasmtime.
Definition: error.hh:24
Error(const std::string &s)
Creates an error with the provided message.
Definition: error.hh:38
Error(wasmtime_error_t *error)
Creates an error from the raw C API representation.
Definition: error.hh:35
wasmtime_error_t * release()
Release ownership of this error, acquiring the underlying C raw pointer.
Definition: error.hh:65
Trace trace() const
Definition: trap.hh:97
std::optional< int32_t > i32_exit() const
Definition: error.hh:51
std::string message() const
Returns the error message associated with this error.
Definition: error.hh:41
Fallible result type used for Wasmtime.
Definition: error.hh:83
const T && ok() const
Returns the success, if present, aborts if this is an error.
Definition: error.hh:104
E && err()
Returns the error, if present, aborts if this is not an error.
Definition: error.hh:97
T unwrap()
Returns the success, if present, aborts if this is an error.
Definition: error.hh:107
T && ok()
Returns the success, if present, aborts if this is an error.
Definition: error.hh:102
Result(T t)
Creates a Result from its successful value.
Definition: error.hh:88
const E && err() const
Returns the error, if present, aborts if this is not an error.
Definition: error.hh:99
Result(E e)
Creates a Result from an error value.
Definition: error.hh:90
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:71
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.