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

build: return ExecErrorCodeGeneric when git operation fails instead of relaying error code directly from git #6092

Merged
merged 1 commit into from
Apr 1, 2025

Conversation

flouthoc
Copy link
Collaborator

@flouthoc flouthoc commented Mar 27, 2025

Only propagate error message from git and let buildah reflect error code
125.

Reason: Buildah should return predicatable error code from the set of
defined error codes in exec_codes.go at https://github.com/containers/buildah/blob/main/pkg/cli/exec_codes.go#L6
anything other that predefined error codes introduces inconsistency thus making testing difficult in CI and podman.

Users should expect buildah to refect ExecErrorCodeGeneric with error message kept intact from the underlying git
commands.

What type of PR is this?

/kind api-change
/kind bug
/kind cleanup
/kind deprecation
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake
/kind other

What this PR does / why we need it:

How to verify it

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

build: return 125 when git operation fails instead of relaying error code directly from git

@nalind
Copy link
Member

nalind commented Mar 27, 2025

Please fill out the description, describing why this is being changed, and describing the user-facing change in terms of what someone running the binary would observe when running it.

@flouthoc
Copy link
Collaborator Author

@nalind Updated commit and PR body.

@nalind
Copy link
Member

nalind commented Mar 27, 2025

My second request was about

Does this PR introduce a user-facing change?

cloneToDirectory: don't relay error code from git

I wouldn't expect someone who wasn't familiar with the implementation to be able to make sense of this.

@flouthoc flouthoc changed the title cloneToDirectory: don't relay error code from git build: return ExecErrorCodeGeneric when git operation fails instead of relaying error code directly from git Mar 27, 2025
@flouthoc
Copy link
Collaborator Author

My second request was about

Does this PR introduce a user-facing change?

cloneToDirectory: don't relay error code from git

I wouldn't expect someone who wasn't familiar with the implementation to be able to make sense of this.

@nalind How about this

build: return ExecErrorCodeGeneric when git operation fails instead of relaying error code directly from git

@@ -267,14 +267,14 @@ func cloneToDirectory(url, dir string) ([]byte, string, error) {
cmd = exec.Command("git", "init", dir)
combinedOutput, err := cmd.CombinedOutput()
if err != nil {
return combinedOutput, gitSubdir, fmt.Errorf("failed while performing `git init`: %w", err)
return combinedOutput, gitSubdir, fmt.Errorf("failed while performing `git init`: %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.

It would likely makes sense to add a comment here (once at least for all four cases) why this is done as this seems like an anti pattern.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Only propagate error message from git and let buildah reflect error code
`125`.

Reason: Buildah should return predicatable error code from the set of
defined error codes in exec_codes.go at https://github.com/containers/buildah/blob/main/pkg/cli/exec_codes.go#L6
anything other that predefined error codes introduces inconsistency thus making testing difficult in CI and podman.

Users should expect buildah to refect ExecErrorCodeGeneric with error message kept intact from the underlying `git`
commands.

Signed-off-by: flouthoc <[email protected]>
@flouthoc flouthoc requested a review from Luap99 March 28, 2025 14:08
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

LGTM

@flouthoc
Copy link
Collaborator Author

@containers/buildah-maintainers PTAL

@nalind
Copy link
Member

nalind commented Apr 1, 2025

I wouldn't expect someone who wasn't familiar with the implementation to be able to make sense of this.

@nalind How about this

build: return ExecErrorCodeGeneric when git operation fails instead of relaying error code directly from git

I wouldn't expect someone who wasn't familiar with the implementation to know what ExecErrorCodeGeneric means, either. Use the number. If we ever want to be able to pull release note information from merged PRs, the writing and the format are going to matter.

@flouthoc
Copy link
Collaborator Author

flouthoc commented Apr 1, 2025

I wouldn't expect someone who wasn't familiar with the implementation to be able to make sense of this.

@nalind How about this

build: return ExecErrorCodeGeneric when git operation fails instead of relaying error code directly from git

I wouldn't expect someone who wasn't familiar with the implementation to know what ExecErrorCodeGeneric means, either. Use the number. If we ever want to be able to pull release note information from merged PRs, the writing and the format are going to matter.

Done edited the release note.

@nalind
Copy link
Member

nalind commented Apr 1, 2025

LGTM

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

/lgtm

Copy link
Contributor

openshift-ci bot commented Apr 1, 2025

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by: flouthoc, Luap99

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

@openshift-merge-bot openshift-merge-bot bot merged commit 32d78c6 into containers:main Apr 1, 2025
37 checks passed
@flouthoc
Copy link
Collaborator Author

flouthoc commented Apr 1, 2025

podman-remote reads the body of the error message and since error body from git contains exit status 128 it parses and sets the error code to 128 causing podman-remote test to fail.

I found this here containers/podman#25756

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants