-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a JsError
type
#1017
Comments
And we should also add a reference page for "Dealing with fallible operations and errors" or some such. |
I don't think it would be very efficient to create a IMO it's easier to just allow arbitrary Then custom conversion will be still possible by providing explicit methods on |
@RReverser hm a good point! I wonder though if perf matters too much in the failure case though? In theory it's rare-ish and it'll already involve a (would be good to measure though!) |
Performance maybe not so much, but given that most exported functions commonly will (hopefully) be returning such |
@RReverser There is a difference in behavior between the two approaches:
This causes a difference in the stack traces. I think both of those approaches are useful, but I don't have an opinion about which one should be the default. |
@Pauan I wasn't suggesting to remove JsError, so there shouldn't be a difference. My approach is merely an optimisation. |
Oh... I see what you are saying I think. You mean that the JS stacktrace inside of WASM itself will look different. I agree, that would be unfortunate. Let's just implement this naïvely first, and then try to optimise. |
@RReverser Yeah, sorry I wasn't more clear. The stack trace is always generated at the time when So if you create a But if you instead don't use Like I said, both behaviors are useful, so I think both should be supported. |
Would love to have something to be able to work with errors properly in wasm! I currently have methods that returns a result with boxed error where i can't add the #[wasm_bindgen]
impl SchemaParser {
#[wasm_bindgen(js_name = "write")]
pub fn wasm_write(&mut self, json: &str) -> Result<(), JsValue> {
// self.write is the function i would like to tag wasm_bindgen, but instead doing this:
match self.write(json) {
Err(e) => Err(JsValue::from_str(&format!("{}", e))),
_ => Ok(()),
}
}
} what would be have real nice to do is just to be able to tag something like this: pub fn write(&mut self, json: &str) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
unimplemented!()
} |
I'm also changing function signatures to All std:: functionality that can't be exposed to the web is hidden. But shared methods still need to return a boxed error. JsValue panics on non-wasm targets, so error handling is - frankly - really annoying. Would be great to change this with something that's supported on both platforms, using the wasm ABI to transmit errors on the heap? |
The local part and the domain are validated on EmailAddress::new. The return type is changed to Option<EmailAddress>. Ideally it should have been `Result<EmailAddress, std::error::Error>`. However, unfortunately it does not seems to be working with wasm_bindgen; refer: rustwasm/wasm-bindgen#1017.
I think this was fixed by #2710. |
Something analogous to
failure::Error
maybe.Easy conversion into a JS value (probably creates a
js_sys::Error
?)Can be the
E
type in aResult<T, E>
that is returned from an exported rust function.Thoughts?
The text was updated successfully, but these errors were encountered: