error-stack: beginner question "confusing backtrace" #3225
-
Hi! I have troubles deciphering the backtraces / error messages that either logging or unwrapping
To me this is completely unintuitive. It does not align how I mentally imagine this to happen chronologically. I am relatively new to both Rust and error-stack so please excuse if I am missing something obvious! Is this how it is intended to look? Am I using this library wrong? Do I have to create a new Error Enum for every single function that the error passes through and change context each time I propagate? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @kwinz
I'm sure you're not the only one with this question and others will thank you for asking it. You're not missing something obvious!
For the consumer of a function, the interesting thing is that the operation did not succeed. In your example, you tried to execute an AT command, that failed. This is the reason the contexts are listed first. Attachments add more information on that context, things that either help to understand the context or can be used later to handle the error properly. Further, the source(s) of the error is listed. This is the reason why your error is misleading: That you tried to execute an AT command is not just purely additive information, it's the context of your error. What you want to see is something like "Could not execute AT command" as a top-level message - that is your actual error. That failed because you had an IO error. The IO error happened because you want to execute a command. (Rule of thumb: An IO error is almost never a top-level error, there is (almost) always more context for what the IO error is the reason for (e.g. you tried opening a file, but it failed because of an IO error.) The ordering of the messages in To summarize: what you probably want is an additional context (maybe
It depends (as usual 😆).
Generally, I hope that helps to understand the idea a bit better. Please feel free to ask if you have any other questions. Also, we're always happy to improve the documentation of |
Beta Was this translation helpful? Give feedback.
I produced a minimal example to simulate your behavior. To make it a little bit easier to deal with the different error kinds I used
thiserror
and a single enum:Given your description of the causes: