-
Notifications
You must be signed in to change notification settings - Fork 18
default error formatting in fn main() -> Result<(),Error>
using Debug instead of Display
#39
Comments
Hey @substack, thank you for opening this issue. We've discussed this issue in the context of stabilizing the That said, we do already have a plan for fixing this. We're going to specialize the The only reason we haven't done this already is because there is a soundness issue when specializing trait implementations that could be conditional based on lifetimes. This will require niko's proposed work around for always applicable trait impls being implemented. Once we have this in place though we hope to update the |
This is where at least some discussion of that happened that led to deciding on I just re-read it, and from what I can tell, I think the thinking was that
I had sadly not realized when this was getting stabilized back then, otherwise I like to think I would have spoken up. Almost right after it stabilized, I asked about reversing course, but it's quite difficult. IIRC, @yaahc has a plan for this, but I can't recall where I read those plans. I can't find them in this repo. Currently, the |
Hmm, could this be changed to work better over an edition change? I would think so since |
Possibly. It might be possible to change how the edition handles the return value of |
Switching to a new #[termination(edition=2018)]
fn main() -> Result<(), impl Debug> {
todo!()
} I think writing an RFC of some sort soon would be good so that we could possibly get it into edition 2021. @yaahc would you be interested in doing that? |
I don't think I can commit to writing another RFC right now, I feel like I'm already at the limit of how much work I can handle and writing has been particularly difficult for me recently. Also, I feel like it's too close to the 2021 edition to be able to really bake a solution to this problem, so I'd prefer to take it slow and aim for the 2024 edition instead, assuming we even want to make this change. I'm hoping that the specialization approach will be sufficient and obviate the need for this proposal. |
Hope it all goes well for you!
Ok, sounds good enough to me! |
It would also be nice to be able to replace Error with something. For example, it's a common pattern to print program name:
|
The default error formatting when you use the
?
operator inmain()
leaves much to be desired. From the output, it appears to useDebug
, which is often automatically derived and will often print very unfriendly walls of characters, especially in combination with the new experimental backtrace api:whereas the Display impl looks pretty good, and very similar to
panic![]
and the formatting I would expect from other languages or gdb:It seems like
Display
is almost always what you want to see in thisfn main()
context (with some very light wrapping to feature-detect for backtraces) if you haven't set up a custom error reporter of your own. After reading through every issue in this repo and many error-related issues in the rust repo, I still have some questions:I think it would be really unfortunate if one of the first things you needed to do when picking up rust is to learn about error reporters so that you can debug your program effectively. Somehow
failure
prints errors in the second format, perhaps by formatting Display-like output in its Debug implementation. Is that also a viable option if we're stuck with Debug infn main()
forever? It's very hard to find information about what is going on with rust errors right now.I have been writing some libraries and I was removing failure since it has been deprecated, but now I am completely at a loss to figure out what I'm supposed to do to provide a nice end-user error experience, as the current core rust behavior seems like a regression over what failure provides.
Here is the program I wrote to reproduce this behavior:
The text was updated successfully, but these errors were encountered: