gdbstub icon indicating copy to clipboard operation
gdbstub copied to clipboard

Improved Error Type (more specificity, fewer semver hazards, etc...)

Open geigerzaehler opened this issue 3 years ago • 1 comments

I recently started experimenting with this crate for AVR. When implementing the target I ran into TargetMismatch errors . The information in those errors was not enough for me to fix the issues—I had to dig through the source code instead.

The first issue was that Arch::Usize was different from what GDB send. To fix the issue I needed to know what GDB expected. The second issue was that Arch::BreakpointKind kind was different from what GDB sent. (I assumed that it would be ()).

What would have helped me to fix this issues faster is an error message pointing to what to fix and how to fix it.

(Happy to provide a PR for this if you want me to.)

geigerzaehler avatar Oct 19 '22 08:10 geigerzaehler

Taking a step back: I think the broader issue here is that there is plenty of room for improvement in gdbstub's error types in general.

I've learned quite a bit about proper error handling in Rust in the years since starting gdbstub, and one thing that's for certain is that you want to have error types that uniquely identify where in the code something failed - something that most certainly isn't the case in the library today.

I spent a bit of time looking through the current code, and honestly - I'm not sure if I have a good "easy" solution off the top of my head. My gut feeling is that the current approach of a single top-level Error enum isn't ideal (it has some semver compat guarantees I'm not a fan of, and isn't particularly well "organized" wrt. different classes of error), and that a more holistic rework of the error type is in order.

That is to say: thanks for the feedback, and for offering to help out with a PR here, but I think this is something I should take a stab at myself at some point :)

daniel5151 avatar Oct 22 '22 18:10 daniel5151