Return js_sys::Error in Wasm
We are losing information when we just stringify the error message.
Proposal
Have all our errors implement a trait that has:
trait IntoJsError {
fn maybe_into_js_error(&self) -> Option<js_sys::JsError>;
}
Then we can extract the inner error if there was one.
There is also the ES stage 3 proposal for error cause which we could use if we wanted. If we decide to do something like that we can create a JsError at the top wasm exit point and attach the underlying error, if any.
@sayrer is there a common trait like TryInto that returns Option instead of Result? Thanks.
Would be super useful to get line numbers if possible, or the current function, or similar. Would have helped with https://github.com/rocicorp/repc/issues/351 bc there are several places in the code where this could be coming from.
@sayrer is there a common trait like
TryIntothat returnsOptioninstead ofResult? Thanks.
I think what you want is this crate: https://crates.io/crates/anyhow (see the downcasting and backtrace support). If that's not right, consider going back to matching on a crate enum, like Rustls does here: https://github.com/ctz/rustls/blob/beef0be1658cd457d4f47039abf4f4bb37d59a78/rustls/src/error.rs#L36
@aboodman I know you have a string opinion about this.
What I want is to return the original JS errors in dispatch. For example if IDB throws I would like that exception to be returned.
But don't you also sort of want the "stack" from Rust too? Ideally?
Wasm is already on the stack. But that would generally not contain meaningful names unless we are doing a profile build. At the moment we do not have a reason to have a non profile build. See https://github.com/rocicorp/replicache/issues/356