human-panic icon indicating copy to clipboard operation
human-panic copied to clipboard

Custom error message

Open naturallymitchell opened this issue 6 years ago • 11 comments

Would it be possible to set a custom error message?

Perhaps a project could have a text file or config file that it passes as a string to human-panic's sourcing of its text.

This would also fix https://github.com/rust-clique/human-panic/issues/7#issuecomment-383035397.

naturallymitchell avatar Jan 25 '19 17:01 naturallymitchell

Here is a similar scenario I met in https://github.com/GreptimeTeam/greptimedb/issues/1165#issuecomment-1804840829.

But given that the Metadata interface is public, we can hack into setup_panic for expanding it manually + write our own print_msg.

The tricky part here is how to customize. But accepting a manner config struct to manipulate may be possible.

I can volunteer to make a demo, but it somehow changes the crate's taste or manner, so I don't want to just dive into it unless the maintainers agree on it and help on reviewing.

cc @epage @spacekookie

tisonkun avatar Nov 09 '23 23:11 tisonkun

If people have ideas on how to improve the default message, I would love for us to focus on that. However, I recognize that there may be cases for improving it. I'd be interested in looking at proposals for how to be customizing the message. This doesn't have to be code. It can be an API with a description on how to affects the text.

epage avatar Nov 10 '23 02:11 epage

The use case I have right now is that I want to specify more ways for users to report an issue:

- Open a support request from the Timescale console:

  https://console.cloud.timescale.com/dashboard/support

- Open a support request by email to [email protected]

- Take your issue to the #migration channel in the community slack, where
  the developers will help:

  https://timescaledb.slack.com/archives/C04PT0Q74EA

I ended up doing it by:

const SUPPORT_MSG: &str = r"https://timescale.com

To submit the crash report:

- Open a support request from the Timescale console:

  https://console.cloud.timescale.com/dashboard/support

- Open a support request by email to [email protected]

- Take your issue to the #migration channel in the community slack, where
  the developers will help:

  https://timescaledb.slack.com/archives/C04PT0Q74EA";

let meta = Metadata {
                version: env!("CARGO_PKG_VERSION").into(),
                name: env!("CARGO_PKG_NAME").into(),
                authors: "".into(),
                homepage: SUPPORT_MSG.into(),
};

alejandrodnm avatar Nov 22 '23 08:11 alejandrodnm

I propose a patch - https://github.com/rust-cli/human-panic/pull/122

There can be a lot of things to be improved, but let's first discuss if the direction is desired.

That is - introduce a Writer/Printer trait for customizing panic message; may or may not we can extend metadata struct later.

The proposed change is backward compatible.

tisonkun avatar Nov 22 '23 12:11 tisonkun

If the focus is on additional links, what if we provided ways for people to extend specifically that?

I'd like for us to share what we can so if things are improved for one, they are improved for all.

epage avatar Nov 27 '23 21:11 epage

If the focus is on additional links, what if we provided ways for people to extend specifically that?

I'd like for us to share what we can so if things are improved for one, they are improved for all.

LGTM. Send #133 for review.

tisonkun avatar Apr 16 '24 11:04 tisonkun