[Feature Request] Support printing of custom panic arguments

I have the following problem: I want to filter out panics which contain personally identifiable information and scrub their messages so that they aren't available in any logs. I added a panic hook, I catch all panics, and if panic matches one of the patterns, I print the panic message.

There's one caveat, I want to have some "safe" message. I want to create a custom type which contains such safe messages, i.e. essentially a newtype around String. However there's a problem. Not all code runs with the custom hook, i.e. unit tests. But if the type isn't &str or String passed to panic_any, it just prints Box.

Is it possible to add a case here: rust/library/std/src/panicking.rs at a34ceade11f62bdef20b86ef37949d3fe00944ef · rust-lang/rust · GitHub So that after checking for &str and String, we check for &dyn Display, and if so, print it?

Is there any reason not to implement it? Would the library team be open to such a change?

1 Like

Downcasting to &dyn Display wouldn't check for arbitrary types implementing Display, it would check for specifically the type dyn Display.

1 Like

@sfackler Ok got it. Thank you. Then. it's not possible :frowning:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.