-
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
add "std-unwrap" feature to defer to std's unwrap in unwrap_throw #3899
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1327,7 +1327,7 @@ pub fn anyref_heap_live_count() -> u32 { | |
pub trait UnwrapThrowExt<T>: Sized { | ||
/// Unwrap this `Option` or `Result`, but instead of panicking on failure, | ||
/// throw an exception to JavaScript. | ||
#[cfg_attr(debug_assertions, track_caller)] | ||
#[cfg_attr(any(debug_assertions, wasm_bindgen_unwrap_throw_debug), track_caller)] | ||
fn unwrap_throw(self) -> T { | ||
if cfg!(all(debug_assertions, feature = "std")) { | ||
let loc = core::panic::Location::caller(); | ||
|
@@ -1346,16 +1346,26 @@ pub trait UnwrapThrowExt<T>: Sized { | |
/// Unwrap this container's `T` value, or throw an error to JS with the | ||
/// given message if the `T` value is unavailable (e.g. an `Option<T>` is | ||
/// `None`). | ||
#[cfg_attr(debug_assertions, track_caller)] | ||
#[cfg_attr(any(debug_assertions, wasm_bindgen_unwrap_throw_debug), track_caller)] | ||
fn expect_throw(self, message: &str) -> T; | ||
} | ||
|
||
impl<T> UnwrapThrowExt<T> for Option<T> { | ||
#[cfg_attr(debug_assertions, track_caller)] | ||
#[cfg(wasm_bindgen_unwrap_throw_debug)] | ||
#[track_caller] | ||
fn unwrap_throw(self) -> T { | ||
self.unwrap() | ||
} | ||
Comment on lines
+1354
to
+1358
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm aware that this is the change proposed in OP, but is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I spend quite a bit of time triaging errors, and in that context consistency and recognisability is important. In this instance, deferring to
We've implemented manual poisoning in our panic hook until #3687 is resolved. The throw inside Anecdotally since switching to this fork various "impossible" errors e.g. rust-lang/regex#1176 have stopped occurring, so in retrospect I think the throwing plus #3687 plus leptos or wasm-bindgen-futures calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm questioning if I do agree that the lack of module poisoning is quite problematic, unfortunately I don't know a "quick" fix for it apart from what you have been doing. I have a couple of suggestions:
Please let me know what you think, I'm sympathetic to your goals but I would like to find a better solution. |
||
|
||
#[cfg_attr(any(debug_assertions, wasm_bindgen_unwrap_throw_debug), track_caller)] | ||
fn expect_throw(self, message: &str) -> T { | ||
if cfg!(all( | ||
target_arch = "wasm32", | ||
not(any(target_os = "emscripten", target_os = "wasi")) | ||
not(any( | ||
wasm_bindgen_unwrap_throw_debug, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above. If you want to include the file, line and column as in |
||
target_os = "emscripten", | ||
target_os = "wasi" | ||
)) | ||
)) { | ||
match self { | ||
Some(val) => val, | ||
|
@@ -1371,11 +1381,15 @@ impl<T, E> UnwrapThrowExt<T> for Result<T, E> | |
where | ||
E: core::fmt::Debug, | ||
{ | ||
#[cfg_attr(debug_assertions, track_caller)] | ||
#[cfg_attr(any(debug_assertions, wasm_bindgen_unwrap_throw_debug), track_caller)] | ||
fn expect_throw(self, message: &str) -> T { | ||
if cfg!(all( | ||
target_arch = "wasm32", | ||
not(any(target_os = "emscripten", target_os = "wasi")) | ||
not(any( | ||
wasm_bindgen_unwrap_throw_debug, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above. |
||
target_os = "emscripten", | ||
target_os = "wasi" | ||
)) | ||
)) { | ||
match self { | ||
Ok(val) => val, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be best if you just remove all guards on
track_caller
, which would also improve native support.