stdweb icon indicating copy to clipboard operation
stdweb copied to clipboard

Should initialize's panic hook work with a `&str` payload?

Open jahredhope opened this issue 5 years ago • 1 comments

Sending a string literal to panic does not print the payload in the console. E.g panic!("My error"); Whereas it does print the message if a String is used. E.g panic!(String::from("My error"));

I'm currently hitting some issues getting started with a cargo-web project. I'm new to a lot of the area so I'm making a lot of mistakes. Unfortunatly, I often don't see the error messages that go along with the errors.

I've noticed initialize helpfully adds a panic hook to expose those errors including: A static message, and (when it has it) a location and an error payload. But I don't appear to see the error payload.

I believe one reason is it appears to try to cast the payload to a String, but PanicInfo seems to indicate it's commonly a String or a &str. https://github.com/koute/stdweb/blob/master/src/webcore/initialization.rs#L28

So code like this would see the message in Console:

#[macro_use]
extern crate stdweb;

fn main() {
  stdweb::initialize();
  panic!(String::from("My error"));
}

But code like this wont:

#[macro_use]
extern crate stdweb;

fn main() {
  stdweb::initialize();
  panic!("My error");
}

jahredhope avatar Jan 18 '21 00:01 jahredhope

@jahredhope your analysis is correct. I managed to create a version which supports both String and &str locally by patching the file you linked, I'll try to issue a PR in the next few days.

Spoonbender avatar Apr 01 '21 16:04 Spoonbender