Skip to content

Add errors to pkg/podman & wrap errors across codebase#482

Closed
martymichal wants to merge 2 commits intocontainers:mainfrom
martymichal:update-error-handling
Closed

Add errors to pkg/podman & wrap errors across codebase#482
martymichal wants to merge 2 commits intocontainers:mainfrom
martymichal:update-error-handling

Conversation

@martymichal
Copy link
Copy Markdown
Member

@martymichal martymichal commented Jun 26, 2020

In a lot of places in the code, we use Go errors in this fashion: fmt.Errorf("container %s...", container). This is alright if we use the error messages immediately and don't care if a function may return different errors. At the moment we need to check for different errors coming from functions, this style becomes bothersome.

This is the most noticeable in the case of removing containers/images. Commands podman rm/rmi may fail with different errors. Either a container/image does not exist or it is running/used. Without dedicated error variables, this is rather hard to catch. We've been going about it by using the approach briefly shown above.

The solution is to add error variables to the package (podman) that can be checked for using the errors (errors.Is and errors.As) library of Go.

The second part of this PR is that in a lot of places in the code, we return errors but don't wrap them around the errors that hold the information about the cause. I encountered this recently when Podman V2 introduced a regression about the option --userns keep-id not working properly. It caused Toolbox to crash (specifically the container entry-point init-container) due to being unable to find info about current user but there was no helpful error message because we dropped it when returning Toolbox's error message.

A good side-effect of this is that commands toolbox rm/rmi now detect if a container is running/image has dependent containers and print a helpful message with a hint on how to delete them.

@softwarefactory-project-zuul
Copy link
Copy Markdown

Build failed.

@martymichal martymichal added this to the Stable 1.0 milestone Jul 7, 2020
@martymichal martymichal added 3. Enhancement Improvement to an existing feature 6. Major Change May cause breakage labels Jul 7, 2020
@martymichal martymichal marked this pull request as draft July 29, 2020 21:05
@martymichal
Copy link
Copy Markdown
Member Author

I created a separate PR (#519) for moving the remove functions. I'll mark this PR as a draft until #519 gets merged.

Using Golang errors with dynamic strings is not very good because it's
very hard to check them. It is much easier to declare package-wide
errors based on which printed error messages are generated. This makes
out job to check for expected/unexpected errors much easier (even though
there's a bit more code for checking and acting upon the different
errors).
When testing for regressions introduced by Podman V2 I encountered an
error with getting information about current user. I had to patch the
toolbox binary to see the underlying error because we do not wrap errors
in most places. Such problems could show again in different places.
@martymichal martymichal force-pushed the update-error-handling branch from 2f20722 to ce6d113 Compare August 22, 2020 18:13
@softwarefactory-project-zuul
Copy link
Copy Markdown

Build failed.

Base automatically changed from master to main March 25, 2021 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. Enhancement Improvement to an existing feature 6. Major Change May cause breakage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant