1 /** 2 * \file wasmtime/error.h 3 * 4 * \brief Definition and accessors of #wasmtime_error_t 5 */ 6 7 #ifndef WASMTIME_ERROR_H 8 #define WASMTIME_ERROR_H 9 10 #include <wasm.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 /** 17 * \typedef wasmtime_error_t 18 * \brief Convenience alias for #wasmtime_error 19 * 20 * \struct wasmtime_error 21 * \brief Errors generated by Wasmtime. 22 * \headerfile wasmtime/error.h 23 * 24 * This opaque type represents an error that happened as part of one of the 25 * functions below. Errors primarily have an error message associated with them 26 * at this time, which you can acquire by calling #wasmtime_error_message. 27 * 28 * Errors are safe to share across threads and must be deleted with 29 * #wasmtime_error_delete. 30 */ 31 typedef struct wasmtime_error wasmtime_error_t; 32 33 /** 34 * \brief Creates a new error with the provided message. 35 */ 36 WASM_API_EXTERN wasmtime_error_t *wasmtime_error_new(const char *); 37 38 /** 39 * \brief Deletes an error. 40 */ 41 WASM_API_EXTERN void wasmtime_error_delete(wasmtime_error_t *error); 42 43 /** 44 * \brief Returns the string description of this error. 45 * 46 * This will "render" the error to a string and then return the string 47 * representation of the error to the caller. The `message` argument should be 48 * uninitialized before this function is called and the caller is responsible 49 * for deallocating it with #wasm_byte_vec_delete afterwards. 50 */ 51 WASM_API_EXTERN void wasmtime_error_message(const wasmtime_error_t *error, 52 wasm_name_t *message); 53 54 /** 55 * \brief Attempts to extract a WASI-specific exit status from this error. 56 * 57 * Returns `true` if the error is a WASI "exit" trap and has a return status. 58 * If `true` is returned then the exit status is returned through the `status` 59 * pointer. If `false` is returned then this is not a wasi exit trap. 60 */ 61 WASM_API_EXTERN bool wasmtime_error_exit_status(const wasmtime_error_t *, 62 int *status); 63 64 /** 65 * \brief Attempts to extract a WebAssembly trace from this error. 66 * 67 * This is similar to #wasm_trap_trace except that it takes a #wasmtime_error_t 68 * as input. The `out` argument will be filled in with the wasm trace, if 69 * present. 70 */ 71 WASM_API_EXTERN void wasmtime_error_wasm_trace(const wasmtime_error_t *, 72 wasm_frame_vec_t *out); 73 74 #ifdef __cplusplus 75 } // extern "C" 76 #endif 77 78 #endif // WASMTIME_ERROR_H 79