-
Notifications
You must be signed in to change notification settings - Fork 248
cmd/rm(i): exit code return fix #1770
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -66,6 +66,8 @@ func rmi(cmd *cobra.Command, args []string) error { | |||||||
| return &exitError{exitCode, err} | ||||||||
| } | ||||||||
|
|
||||||||
| errCount := 0 | ||||||||
|
|
||||||||
| if rmiFlags.deleteAll { | ||||||||
| toolboxImages, err := getImages(false) | ||||||||
| if err != nil { | ||||||||
|
|
@@ -76,6 +78,7 @@ func rmi(cmd *cobra.Command, args []string) error { | |||||||
| imageID := image.ID | ||||||||
| if err := podman.RemoveImage(imageID, rmiFlags.forceDelete); err != nil { | ||||||||
| fmt.Fprintf(os.Stderr, "Error: %s\n", err) | ||||||||
| errCount++ | ||||||||
| continue | ||||||||
| } | ||||||||
| } | ||||||||
|
|
@@ -92,16 +95,23 @@ func rmi(cmd *cobra.Command, args []string) error { | |||||||
| for _, image := range args { | ||||||||
| if _, err := podman.IsToolboxImage(image); err != nil { | ||||||||
| fmt.Fprintf(os.Stderr, "Error: %s\n", err) | ||||||||
| errCount++ | ||||||||
| continue | ||||||||
| } | ||||||||
|
|
||||||||
| if err := podman.RemoveImage(image, rmiFlags.forceDelete); err != nil { | ||||||||
| fmt.Fprintf(os.Stderr, "Error: %s\n", err) | ||||||||
| errCount++ | ||||||||
| continue | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| if errCount != 0 { | ||||||||
| errMsg := fmt.Sprintf("failed to remove %d images", errCount) | ||||||||
| return errors.New(errMsg) | ||||||||
|
Comment on lines
+111
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency and to be more idiomatic, consider using
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw a lot of places using But I am not against using it :) |
||||||||
| } | ||||||||
|
|
||||||||
| return nil | ||||||||
| } | ||||||||
|
|
||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message
failed to removemight not be fully accurate in all cases, aserrCountis also incremented for inspection failures or if a container is not a Toolbx container. A more generic message would be more appropriate. Also, you can usefmt.Errorfto create a formatted error directly, which is more idiomatic in Go.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is true that we can encounter errors that may prevent us from even calling
podmanto remove themBut my reasoning for still sticking with the
failed to removeerror was:Any error encountered during the removal process prevents the container or image from being removed. So, in essence, isn’t it a failure of the removal process as a whole?