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

Fix, and reduce repetitiveness, in container cleanup error handling #18636

Merged
merged 3 commits into from
May 23, 2023

Conversation

mtrmac
Copy link
Collaborator

@mtrmac mtrmac commented May 19, 2023

https://github.com/containers/podman/pull/18634/checks?check_run_id=13617533713 contains a failure with

cleaning up container … storage: %!w(<nil>)

Fix that nil usage; then look at the pattern, and replace copy&pasted logic with helpers, at the cost of changing the error / log messages a bit.

See individual commits for more details. If you’d prefer just the two-line bug fix without the other changes, that’s fine with me too.

Does this PR introduce a user-facing change?

None

@openshift-ci openshift-ci bot added release-note-none approved Indicates a PR has been approved by an approver from all required OWNERS files. labels May 19, 2023
@rhatdan
Copy link
Member

rhatdan commented May 19, 2023

LGTM

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better than before. Thanks, @mtrmac

LGTM

@openshift-ci
Copy link
Contributor

openshift-ci bot commented May 22, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mtrmac, vrothberg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@vrothberg
Copy link
Member

To pass CI, can you add the magic '[NO NEW TESTS NEEDED]' string to your commit message?

Comment on lines +1819 to +1826
reportErrorf := func(msg string, args ...any) {
err := fmt.Errorf(msg, args...) // Always use fmt.Errorf instead of just logrus.Errorf(…) because the format string probably contains %w
if cleanupErr == nil {
cleanupErr = err
} else {
logrus.Errorf("%s", err.Error())
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice but maybe to avoid duplicating this function in wto palces we could export this to another function which just accepts cleanupErr as arg and then returns this anonymous function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not familiar with the codebase and I’m fine with making whatever adjustments are requested. I’ll just push back a bit, once :)


My general impression is that this, ~silently proceeding on failures, is a fairly unusual error handling model, and I’m not too enthusiastic about codifying this approach and making it look like an approach to be followed elsewhere. In some ideal end state (which we could never test properly), I imagine we would track which parts of the cleanup succeeded and which are still outstanding, so that the user can re-start the cleanup and get the other parts done.

(Also, so far there are only two functions that use it. My personal, not at all evidence-based, rule of thumb is to consolidate at 3 instances.)

mtrmac added 3 commits May 22, 2023 19:11
[NO NEW TESTS NEEDED]
... because testing this would require us to intentionally
create an inconsistent state, which should ideally not be possible...
(and because at this point I don't even know what the reported failure
was.)

Signed-off-by: Miloslav Trmač <[email protected]>
Use a shared helper instead of copy&pasting the handling
of cleanupErr EIGHT times.

This changes the wording of logged error text, and the error
in one case, a bit.

Signed-off-by: Miloslav Trmač <[email protected]>
Use a helper to handle the cleanupErr logic instead of
copy&pasting it EIGHT times.

Also modifies the returned errors to be wrapped with a context,
and changes the text of the logged errors a bit.

Signed-off-by: Miloslav Trmač <[email protected]>
@mtrmac mtrmac force-pushed the cleanupStorage-error branch from 3d72d2f to 032d4a9 Compare May 22, 2023 17:14
@TomSweeneyRedHat
Copy link
Member

Once the location of the new function is determined, the rest of the code LGTM. Nice condensation @mtrmac !

@Luap99
Copy link
Member

Luap99 commented May 23, 2023

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label May 23, 2023
@openshift-merge-robot openshift-merge-robot merged commit fe64f79 into containers:main May 23, 2023
@mtrmac mtrmac deleted the cleanupStorage-error branch May 23, 2023 16:18
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Aug 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants