Skip to content

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

Description

@jahredhope

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");
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions