* \brief Errors coming from Wasmtime * * This class represents an error that came from Wasmtime and contains a textual * description of the error that occurred. */
| 24 | * description of the error that occurred. |
| 25 | */ |
| 26 | class Error { |
| 27 | WASMTIME_OWN_WRAPPER(Error, wasmtime_error); |
| 28 | |
| 29 | /// \brief Creates an error with the provided message. |
| 30 | Error(const std::string &s) : ptr(wasmtime_error_new(s.c_str())) {} |
| 31 | |
| 32 | /// \brief Returns the error message associated with this error. |
| 33 | std::string message() const { |
| 34 | wasm_byte_vec_t msg_bytes; |
| 35 | wasmtime_error_message(ptr.get(), &msg_bytes); |
| 36 | auto ret = std::string(msg_bytes.data, msg_bytes.size); |
| 37 | wasm_byte_vec_delete(&msg_bytes); |
| 38 | return ret; |
| 39 | } |
| 40 | |
| 41 | /// If this trap represents a call to `exit` for WASI, this will return the |
| 42 | /// optional error code associated with the exit trap. |
| 43 | std::optional<int32_t> i32_exit() const { |
| 44 | int32_t status = 0; |
| 45 | if (wasmtime_error_exit_status(ptr.get(), &status)) { |
| 46 | return status; |
| 47 | } |
| 48 | return std::nullopt; |
| 49 | } |
| 50 | |
| 51 | /// Returns the trace of WebAssembly frames associated with this error. |
| 52 | /// |
| 53 | /// Note that the `trace` cannot outlive this error object. |
| 54 | Trace trace() const; |
| 55 | }; |
| 56 | |
| 57 | /// \brief Used to print an error. |
| 58 | inline std::ostream &operator<<(std::ostream &os, const Error &e) { |
no outgoing calls