17a1b7cdfSAlex Crichton /** 27a1b7cdfSAlex Crichton * \file wasmtime/error.h 37a1b7cdfSAlex Crichton * 47a1b7cdfSAlex Crichton * \brief Definition and accessors of #wasmtime_error_t 57a1b7cdfSAlex Crichton */ 67a1b7cdfSAlex Crichton 77a1b7cdfSAlex Crichton #ifndef WASMTIME_ERROR_H 87a1b7cdfSAlex Crichton #define WASMTIME_ERROR_H 97a1b7cdfSAlex Crichton 107a1b7cdfSAlex Crichton #include <wasm.h> 117a1b7cdfSAlex Crichton 127a1b7cdfSAlex Crichton #ifdef __cplusplus 137a1b7cdfSAlex Crichton extern "C" { 147a1b7cdfSAlex Crichton #endif 157a1b7cdfSAlex Crichton 167a1b7cdfSAlex Crichton /** 177a1b7cdfSAlex Crichton * \typedef wasmtime_error_t 187a1b7cdfSAlex Crichton * \brief Convenience alias for #wasmtime_error 197a1b7cdfSAlex Crichton * 207a1b7cdfSAlex Crichton * \struct wasmtime_error 217a1b7cdfSAlex Crichton * \brief Errors generated by Wasmtime. 227a1b7cdfSAlex Crichton * \headerfile wasmtime/error.h 237a1b7cdfSAlex Crichton * 247a1b7cdfSAlex Crichton * This opaque type represents an error that happened as part of one of the 257a1b7cdfSAlex Crichton * functions below. Errors primarily have an error message associated with them 267a1b7cdfSAlex Crichton * at this time, which you can acquire by calling #wasmtime_error_message. 277a1b7cdfSAlex Crichton * 287a1b7cdfSAlex Crichton * Errors are safe to share across threads and must be deleted with 297a1b7cdfSAlex Crichton * #wasmtime_error_delete. 307a1b7cdfSAlex Crichton */ 317a1b7cdfSAlex Crichton typedef struct wasmtime_error wasmtime_error_t; 327a1b7cdfSAlex Crichton 337a1b7cdfSAlex Crichton /** 34cfb506baStheothergraham * \brief Creates a new error with the provided message. 35cfb506baStheothergraham */ 36cfb506baStheothergraham WASM_API_EXTERN wasmtime_error_t *wasmtime_error_new(const char *); 37cfb506baStheothergraham 38cfb506baStheothergraham /** 397a1b7cdfSAlex Crichton * \brief Deletes an error. 407a1b7cdfSAlex Crichton */ 417a1b7cdfSAlex Crichton WASM_API_EXTERN void wasmtime_error_delete(wasmtime_error_t *error); 427a1b7cdfSAlex Crichton 437a1b7cdfSAlex Crichton /** 447a1b7cdfSAlex Crichton * \brief Returns the string description of this error. 457a1b7cdfSAlex Crichton * 467a1b7cdfSAlex Crichton * This will "render" the error to a string and then return the string 477a1b7cdfSAlex Crichton * representation of the error to the caller. The `message` argument should be 487a1b7cdfSAlex Crichton * uninitialized before this function is called and the caller is responsible 497a1b7cdfSAlex Crichton * for deallocating it with #wasm_byte_vec_delete afterwards. 507a1b7cdfSAlex Crichton */ 51*f8fee938STyler Rockwood WASM_API_EXTERN void wasmtime_error_message(const wasmtime_error_t *error, 52*f8fee938STyler Rockwood wasm_name_t *message); 537a1b7cdfSAlex Crichton 54b07b0676SAlex Crichton /** 55b07b0676SAlex Crichton * \brief Attempts to extract a WASI-specific exit status from this error. 56b07b0676SAlex Crichton * 57b07b0676SAlex Crichton * Returns `true` if the error is a WASI "exit" trap and has a return status. 58b07b0676SAlex Crichton * If `true` is returned then the exit status is returned through the `status` 59b07b0676SAlex Crichton * pointer. If `false` is returned then this is not a wasi exit trap. 60b07b0676SAlex Crichton */ 61*f8fee938STyler Rockwood WASM_API_EXTERN bool wasmtime_error_exit_status(const wasmtime_error_t *, 62*f8fee938STyler Rockwood int *status); 63b07b0676SAlex Crichton 64b07b0676SAlex Crichton /** 65b07b0676SAlex Crichton * \brief Attempts to extract a WebAssembly trace from this error. 66b07b0676SAlex Crichton * 67b07b0676SAlex Crichton * This is similar to #wasm_trap_trace except that it takes a #wasmtime_error_t 68b07b0676SAlex Crichton * as input. The `out` argument will be filled in with the wasm trace, if 69b07b0676SAlex Crichton * present. 70b07b0676SAlex Crichton */ 71*f8fee938STyler Rockwood WASM_API_EXTERN void wasmtime_error_wasm_trace(const wasmtime_error_t *, 72*f8fee938STyler Rockwood wasm_frame_vec_t *out); 73b07b0676SAlex Crichton 747a1b7cdfSAlex Crichton #ifdef __cplusplus 757a1b7cdfSAlex Crichton } // extern "C" 767a1b7cdfSAlex Crichton #endif 777a1b7cdfSAlex Crichton 787a1b7cdfSAlex Crichton #endif // WASMTIME_ERROR_H 79