Skip to content

Wrap underlying errors with %w instead of %v#896

Open
arpitjain099 wants to merge 1 commit into
slsa-framework:mainfrom
arpitjain099:chore/wrap-multiple-errors-692
Open

Wrap underlying errors with %w instead of %v#896
arpitjain099 wants to merge 1 commit into
slsa-framework:mainfrom
arpitjain099:chore/wrap-multiple-errors-692

Conversation

@arpitjain099

Copy link
Copy Markdown

Addresses #692.

Go 1.20 added support for wrapping multiple errors in a single fmt.Errorf, which the issue (following the discussion on #691) suggested adopting across the code.

This converts the fmt.Errorf("%w: %v", sentinel, err) sites whose second argument is actually an error, so the underlying cause is wrapped too and errors.Is/errors.As can match it rather than only the sentinel:

  • gcb/provenance.go (invalid DSSE payload, mismatched tag and versioned-tag) and gha/builder.go (untrusted reusable workflow) now wrap their err with %w. The two signature-verification paths in gcb/provenance.go and utils/dsse.go that accumulate a []error now join them with errors.Join(errs...), so every collected failure stays inspectable instead of being flattened into a string.
  • The err.Error() arguments became plain err so the chain is preserved.

Sites whose second argument is a plain string (package name, build type, builder ID, config URI) are left as %v, since there is no error to wrap there.

go build, go vet, and the gcb/utils package tests pass locally.

Go 1.20 allows wrapping multiple errors in one fmt.Errorf. Convert the "%w: %v" sites whose second argument is an error to "%w: %w" so errors.Is/As match the underlying cause, not just the sentinel; accumulated []error cases are combined with errors.Join. Sites whose second argument is a plain string keep %v.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@arpitjain099 arpitjain099 requested a review from a team as a code owner June 10, 2026 02:16
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.

1 participant