Module wasmer_c_api::error
source · Expand description
Utilities to read errors.
Only one error can be registered at a time. Error are registered by Rust only, and are usually read by C or C++.
Reading an error from C or C++ happens in 2 steps: Getting the
error’s length with wasmer_last_error_length
, and then reading
the actual error with wasmer_last_error_message
.
§Example
int main() {
// Create an invalid WebAssembly module from a WAT definition,
// it will generate an error!
wasm_byte_vec_t wat;
wasmer_byte_vec_new_from_string(&wat, "(foobar)");
wasm_byte_vec_t wasm;
wat2wasm(&wat, &wasm);
int error_length = wasmer_last_error_length();
// There is an error!
assert(error_length > 0);
char *error_message = malloc(error_length);
wasmer_last_error_message(error_message, error_length);
printf("Error message: %s\n", error_message);
// Side note: The error has now been cleared on the Rust side!
assert(wasmer_last_error_length() == 0);
// Free everything.
free(error_message);
wasm_byte_vec_delete(&wasm);
wasm_byte_vec_delete(&wat);
return 0;
}
Functions§
- Rust function to register a new error.
- Gets the length in bytes of the last error if any, zero otherwise. This includes th NUL terminator byte.
- Gets the last error message if any into the provided buffer
buffer
up to the givenlength
.