repc icon indicating copy to clipboard operation
repc copied to clipboard

Return js_sys::Error in Wasm

Open arv opened this issue 4 years ago • 6 comments

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 avatar May 19 '21 18:05 arv

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

arv avatar May 19 '21 18:05 arv

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.

phritz avatar May 19 '21 20:05 phritz

@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

sayrer avatar May 20 '21 01:05 sayrer

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

arv avatar May 22 '21 18:05 arv

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

aboodman avatar May 22 '21 18:05 aboodman

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

arv avatar May 22 '21 19:05 arv