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 Deletes an error. 35 */ 36 WASM_API_EXTERN void wasmtime_error_delete(wasmtime_error_t *error); 37 38 /** 39 * \brief Returns the string description of this error. 40 * 41 * This will "render" the error to a string and then return the string 42 * representation of the error to the caller. The `message` argument should be 43 * uninitialized before this function is called and the caller is responsible 44 * for deallocating it with #wasm_byte_vec_delete afterwards. 45 */ 46 WASM_API_EXTERN void wasmtime_error_message( 47 const wasmtime_error_t *error, 48 wasm_name_t *message 49 ); 50 51 /** 52 * \brief Attempts to extract a WASI-specific exit status from this error. 53 * 54 * Returns `true` if the error is a WASI "exit" trap and has a return status. 55 * If `true` is returned then the exit status is returned through the `status` 56 * pointer. If `false` is returned then this is not a wasi exit trap. 57 */ 58 WASM_API_EXTERN bool wasmtime_error_exit_status(const wasmtime_error_t*, int *status); 59 60 /** 61 * \brief Attempts to extract a WebAssembly trace from this error. 62 * 63 * This is similar to #wasm_trap_trace except that it takes a #wasmtime_error_t 64 * as input. The `out` argument will be filled in with the wasm trace, if 65 * present. 66 */ 67 WASM_API_EXTERN void wasmtime_error_wasm_trace(const wasmtime_error_t*, wasm_frame_vec_t *out); 68 69 #ifdef __cplusplus 70 } // extern "C" 71 #endif 72 73 #endif // WASMTIME_ERROR_H 74