Skip to content
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

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

Open
jahredhope opened this issue Jan 18, 2021 · 1 comment
Open

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

jahredhope opened this issue Jan 18, 2021 · 1 comment

Comments

@jahredhope
Copy link

jahredhope commented Jan 18, 2021

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");
}
@Spoonbender
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants