rocicorp / repc

The canonical Replicache client, implemented in Rust.
Other
31 stars 7 forks source link

Return js_sys::Error in Wasm #352

Open arv opened 3 years ago

arv commented 3 years ago

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.

arv commented 3 years ago

@sayrer is there a common trait like TryInto that returns Option instead of Result? Thanks.

phritz commented 3 years ago

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 commented 3 years ago

@sayrer is there a common trait like TryInto that returns Option instead of Result? 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

arv commented 3 years ago

@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.

aboodman commented 3 years ago

But don't you also sort of want the "stack" from Rust too? Ideally?

arv commented 3 years ago

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