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

Handle failures more consistently via clar_abort() #101

Merged
merged 6 commits into from
Sep 20, 2024

Conversation

pks-t
Copy link
Member

@pks-t pks-t commented Sep 5, 2024

Failures are being treated somewhat inconsistently throughout the clar codebase. Introduce a new function clar_abort() and adapt our error handling to use it consistently.

@pks-t pks-t requested a review from ethomson September 5, 2024 09:08
In almost all cases, a call to `clar_print_onabort()` is immediately
followed by a call to `exit(-1)`. Add a new function `clar_abort()` that
combines these two steps into one and convert callsites to use it.

While at it, adapt the error messages to be consistent with trailing
punctuation and newlines as well as more informative by including both
potential arguments and the errno.
When initializing a summary fails we first call `perror()` followed by
`clar_abort()`. This is somewhat broken because the second function call
will always claim that opening the file has failed, even though the
failure may actually be that we are out of memory.

Fix this by using `clar_abort()` in `clar_summary_init()` directly,
which gives direct access to the failures' root cause. Callers do not
need to check for errors anymore.
The function `clar_sandbox()` can fail either because it failed to build
a sandbox path or because it failed to change directories into it. The
error reporting happens at the callsite of this function though, where
we are unable to distinguish those two root causes.

Adapt the code to instead perform error handling via `clar_abort()` in
`clar_sandbox()` itself. This gives us direct access to the root cause.
Callers do not need to check for errors anymore.
We're not consistently checking for failing calls to `calloc()`. Do so
and adapt all callsites to use `clar_abort()`.
We're not checking for failing calls to `strdup()`. Fix this.
We have a single callsite of `assert()` remaining in our codebase that
checks for unknown command line arguments. This is somewhat broken
though as asserts may not be compiled depending on how the code is
compiled. Consequently, we may not abort properly on invalid arguments
in some scenarios.

Fix this issue by using `clar_abort()` instead.
@pks-t
Copy link
Member Author

pks-t commented Sep 20, 2024

Rebased on top of #100.

@pks-t pks-t self-assigned this Sep 20, 2024
@ethomson ethomson merged commit 9007d48 into clar-test:main Sep 20, 2024
5 checks passed
@ethomson
Copy link
Member

Thanks!

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.

2 participants