-
-
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
Allow for returning custom error type in Result #1004
Comments
Indeed allowing something other than just a One idea @fitzgen and I had awhile back was to add some sort of error type to wasm-bindgen that you can I think though if we did I'm curious though, would such an error cover your use case? |
My use case is laziness :) It would be ideal for me if I can just sprinkle my existing library with a few well placed Things are amazing close to this now, thanks to the awesome work here by you and others! It really was day and night compared to hand rolling an FFI crate. I would love to see a similar approach to auto-generating FFI functions and C++ / otherlang bindings in the future. I guess I'm not quite sure what the best practices as far as using |
Ah ok, thanks for the info! I think this is definitely a use case we haven't really explored all that well, reusing existing crates as-is and exporting them to JS. I don't think I'm opposed to doing this, and it may even be possible with a custom error strategy in wasm-bindgen itself (as we could just implement If you' curious to give this a shot, want to test this out in a local patch and see how hard it would be to implement in wasm-bindgen? I suspect the implementation might actually be somewhat localized and easy to do test! |
cc #1017 as well |
My one concern with allowing arbitrary E.g. I myself found out only by accident that I was throwing literally strings when doing Hence, #1017 sounds like a better solution for this IMO. |
That's a compelling rationale to me! I think we'd probably at least limit this to |
This was fixed in #2710 (anything which implements |
The docs need to be updated, as https://rustwasm.github.io/wasm-bindgen/reference/types/result.html still says only |
Resolves rustwasm#1004 rustwasm#2710 added support for returning `Result<T, impl Into<JsValue>>` rather than just `Result<T, JsValue>`, but the `wasm-bindgen` guide still claims that only the latter is supported. This fixes that, and also fixes a mistake in the table for what forms `Result` can be returned in (it previously claimed that only `Option<Result<...>>` was supported, when in fact only a plain `Result<...>` is supported).
Resolves #1004 #2710 added support for returning `Result<T, impl Into<JsValue>>` rather than just `Result<T, JsValue>`, but the `wasm-bindgen` guide still claims that only the latter is supported. This fixes that, and also fixes a mistake in the table for what forms `Result` can be returned in (it previously claimed that only `Option<Result<...>>` was supported, when in fact only a plain `Result<...>` is supported).
Currently only
Result<T, JsValue>
is allowed, would it be reasonable to change this toResult<T, I>
so long asI: Into<JsValue>
to allow custom error types to be returned?Happy to open a PR if this makes sense
The text was updated successfully, but these errors were encountered: