Description
Describe the Bug
I was debating between creating this issue as a feature request or as a bug, but I do believe it is a bug, as it is not what I would believe to be the intended behavior.
Currently, when calling unwrap_throw()
or expect_throw()
on an Err(E)
variant, where E: Debug
, only the message is printed, and not the debug value of E
, as it does for the regular expect()
/unwrap()
counterparts. This makes the thrown error much less usable in diagnostics, especially since the unwrap_throw
does not provide the std::panic:Location
to hint as to what went wrong and where.
If this is, perhaps, a security concern, a feature flag might make this functionality available, and keep the old behavior when this flag is not set. Although, I am behind the idea of mimicking the original functions behavior when it comes to the thrown message.
Steps to Reproduce
- Try the following code:
use wasm_bindgen::prelude::*;
#[wasm_bindgen(start)]
fn start() {
let res: Result<(), String> = Err("This message should be displayed when thrown".to_string());
res.expect_throw("Throwing error...");
// or
res.unwrap_throw();
}
Expected Behavior
The unwrap_throw()
/expect_throw()
trait methods should mimic the behavior of the core
/std
library, displaying a debug view of the contained error value.
Actual Behavior
The expect_throw()
method only displays the message in the thrown error, and neither unwrap_throw()
nor expect_throw()
display a std::panic::Location
to trace the origin of the thrown error.