You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a Result<> is returned from a function exposed to js via #[wasm_bindgen], the error is returned as an Exception.
Since panics also cause Exceptions, there is no way to tell if an Exception was caused by an expected error or a panic.
This matters because panics can potentially result in a corrupted wasm instance and should be handled by re-initializing a new wasm instance. Expected errors on the other hand (for example, the result of invalid user input) don't require re-initializing the entire wasm as they are just part of regular business logic.
For this reason, we would rather return expected errors as part of the Ok of this Result, instead of the Error.
When a
Result<>
is returned from a function exposed to js via#[wasm_bindgen]
, the error is returned as an Exception.Since panics also cause Exceptions, there is no way to tell if an Exception was caused by an expected error or a panic.
This matters because panics can potentially result in a corrupted wasm instance and should be handled by re-initializing a new wasm instance. Expected errors on the other hand (for example, the result of invalid user input) don't require re-initializing the entire wasm as they are just part of regular business logic.
For this reason, we would rather return expected errors as part of the
Ok
of this Result, instead of theError
.So something like this:
Would become something like this:
The text was updated successfully, but these errors were encountered: