-
Notifications
You must be signed in to change notification settings - Fork 313
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
Revisit panicking in std::fmt::Display
implementations as a footgun
#667
Comments
std::fmt::Display
implementationsstd::fmt::Display
implementations as a footgun
This definitely is a footgun. We panic in two @phimuemue I would be in favor of formatting an error message rather than panicking. |
I agree it is concerning that our I think that people rely on the output of So, we could rename it to Possibly off-topic: I am unsure, but may the general problem the following:
Then, you could - theoretically, and possibly using specialization - |
I see your point on incorrectness for Would it help enough to panic with a big CAPS error message then? For the user to easily find it in a possibly large log?
We are not using const-generics yet so use specialization seems like an eternity to me at the moment. But it would be nicer! |
We have to make a judgement call here. We must admit there isn't a perfect solution for this problem. We just have to pick our poison. I already personally consider I don't think |
So merely update the docs, easy enough. |
If you mean formatting a CAPS message as output of display instead of panicking, that would also be cool, but I also see the point in producing a hard panic that would be much more visible than that (unless you use |
Oops, I meant panicking with an error message in CAPS like |
Caps letters would be more visible indeed, but it wouldn't help in the case that I reported in my issue where the panic message was totally not visible because |
Panicking in
std::fmt::Display
implementations is a glaring footgun. Here is an example, where you are guaranteed to spend several hours debugging it, and potentially you will never find a cause because the panic happens in production deeply inside the logging system, which is your eyes, but they are now blind. Also, you won't notice this during development, because this log statement occurs in some obscure error-handling code which is hit 0.00001% of the time:With this you'll see only this log output without any indication of panic:
Solution
Don't panic in
std::fmt::Display
implementations. Instead, the best approach would be to format a message with a lot of CAPS letters that say what the problem there is in the rendered message. Or panicking behavior could be made conditional upon a feature flag or maybe some other way of configuration, like a global variable or setup functionThe text was updated successfully, but these errors were encountered: