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

replace hashicorp/go-multierror with errors.Join #778

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/oci-runtime-tool/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var bundleValidateCommand = cli.Command{
logrus.Warn(e)
}

return levelErrors.Error.ErrorOrNil()
return levelErrors.Error
}
fmt.Println("Bundle validation succeeded.")
return nil
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.19
require (
github.com/blang/semver/v4 v4.0.0
github.com/google/uuid v1.3.0
github.com/hashicorp/go-multierror v1.1.1
github.com/mndrix/tap-go v0.0.0-20171203230836-629fa407e90b
github.com/mrunalp/fileutils v0.5.0
github.com/opencontainers/runtime-spec v1.1.0
Expand All @@ -20,7 +19,6 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/mndrix/tap-go v0.0.0-20171203230836-629fa407e90b h1:Ga1nclDSe8gOw37MVLMhfu2QKWtD6gvtQ298zsKVh8g=
github.com/mndrix/tap-go v0.0.0-20171203230836-629fa407e90b/go.mod h1:pzzDgJWZ34fGzaAZGFW22KVZDfyrYW+QABMrWnJBnSs=
github.com/mrunalp/fileutils v0.5.0 h1:NKzVxiH7eSk+OQ4M+ZYW1K6h27RUV3MI6NUTsHhU6Z4=
Expand Down
40 changes: 21 additions & 19 deletions specerror/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
package specerror

import (
"errors"
"fmt"

"github.com/hashicorp/go-multierror"
rfc2119 "github.com/opencontainers/runtime-tools/error"
)

Expand Down Expand Up @@ -43,7 +43,7 @@

// Error holds errors that were at or above a compliance-level
// threshold, as well as errors that are not Errors.
Error *multierror.Error
Error error
}

var ociErrors = map[Code]errorTemplate{}
Expand Down Expand Up @@ -107,6 +107,10 @@
}
}

type joinErr interface {
Unwrap() []error
}

// FindError finds an error from a source error (multiple error) and
// returns the error code if found.
// If the source error is nil or empty, return NonError.
Expand All @@ -115,16 +119,14 @@
if err == nil {
return NonError
}

if merr, ok := err.(*multierror.Error); ok {
if merr.ErrorOrNil() == nil {
return NonError
}
for _, e := range merr.Errors {
if rfcErr, ok := e.(*Error); ok {
if rfcErr.Code == code {
return code
}
var rfcErr *Error
if errors.As(err, &rfcErr) && rfcErr.Code == code {
return code
}
if errs, ok := err.(joinErr); ok {
for _, e := range errs.Unwrap() {
if errors.As(e, &rfcErr) && rfcErr.Code == code {
return code
}
}
}
Expand All @@ -135,18 +137,18 @@
// from the source error. If the source error is not a multierror, it
// is returned unchanged.
func SplitLevel(errIn error, level rfc2119.Level) (levelErrors LevelErrors, errOut error) {
merr, ok := errIn.(*multierror.Error)
errs, ok := errIn.(joinErr)
if !ok {
return levelErrors, errIn
}
for _, err := range merr.Errors {
e, ok := err.(*Error)
if ok && e.Err.Level < level {
fmt.Println(e)
levelErrors.Warnings = append(levelErrors.Warnings, e)
for _, err := range errs.Unwrap() {
var rfcErr *Error
if errors.As(err, &rfcErr) && rfcErr.Err.Level < level {
fmt.Println(rfcErr)
levelErrors.Warnings = append(levelErrors.Warnings, rfcErr)
continue
}
levelErrors.Error = multierror.Append(levelErrors.Error, err)
levelErrors.Error = errors.Join(levelErrors.Error, err)

Check failure on line 151 in specerror/error.go

View workflow job for this annotation

GitHub Actions / test (1.19.x, -race)

undefined: errors.Join

Check failure on line 151 in specerror/error.go

View workflow job for this annotation

GitHub Actions / test (1.19.x)

undefined: errors.Join
}
return levelErrors, nil
}
Loading
Loading