Skip to content
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

libdrgn: add drgn_error_catch() #352

Closed
wants to merge 1 commit into from
Closed

Conversation

brenns10
Copy link
Contributor

A common enough pattern is to catch errors by their code, and then destroy them and handle them in some way. Add a helper to handle this. The helper always destroys the error and always NULLs the error pointer (which may otherwise be left to point at a stale error).

A less common short-cut is to directly compare error values to global error variables. In particular, "err == &drgn_not_found" should really be replaced with a catch statement that catches all DRGN_ERROR_LOOKUP. However, the others (drgn_stop, drgn_line_wrap, and drgn_enomem) are specialized enough that they probably don't merit this treatment.

Apply the new helper to the whole codebase.

A common enough pattern is to catch errors by their code, and then
destroy them and handle them in some way. Add a helper to handle this.
The helper always destroys the error and always NULLs the error
pointer (which may otherwise be left to point at a stale error).

A less common short-cut is to directly compare error values to global
error variables. In particular, "err == &drgn_not_found" should really
be replaced with a catch statement that catches all DRGN_ERROR_LOOKUP.
However, the others (drgn_stop, drgn_line_wrap, and drgn_enomem) are
specialized enough that they probably don't merit this treatment.

Apply the new helper to the whole codebase.

Signed-off-by: Stephen Brennan <[email protected]>
@brenns10
Copy link
Contributor Author

brenns10 commented Nov 9, 2023

I still think this is a good idea but will need to be redone given all the changes that have happened in main. I'll pick up this idea at a later date. Keeping the branch around for reference though.

@brenns10 brenns10 closed this Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant