Skip to content

Commit 7769afa

Browse files
committed
replace hashicorp/go-multierror with errors.Join
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent f7e3563 commit 7769afa

File tree

22 files changed

+169
-1623
lines changed

22 files changed

+169
-1623
lines changed

cmd/oci-runtime-tool/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var bundleValidateCommand = cli.Command{
4545
logrus.Warn(e)
4646
}
4747

48-
return levelErrors.Error.ErrorOrNil()
48+
return levelErrors.Error
4949
}
5050
fmt.Println("Bundle validation succeeded.")
5151
return nil

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.19
55
require (
66
github.com/blang/semver/v4 v4.0.0
77
github.com/google/uuid v1.3.0
8-
github.com/hashicorp/go-multierror v1.1.1
98
github.com/mndrix/tap-go v0.0.0-20171203230836-629fa407e90b
109
github.com/mrunalp/fileutils v0.5.0
1110
github.com/opencontainers/runtime-spec v1.1.0
@@ -20,7 +19,6 @@ require (
2019

2120
require (
2221
github.com/davecgh/go-spew v1.1.1 // indirect
23-
github.com/hashicorp/errwrap v1.0.0 // indirect
2422
github.com/pmezard/go-difflib v1.0.0 // indirect
2523
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
2624
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
55
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
66
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
77
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
8-
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
9-
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
10-
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
11-
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
128
github.com/mndrix/tap-go v0.0.0-20171203230836-629fa407e90b h1:Ga1nclDSe8gOw37MVLMhfu2QKWtD6gvtQ298zsKVh8g=
139
github.com/mndrix/tap-go v0.0.0-20171203230836-629fa407e90b/go.mod h1:pzzDgJWZ34fGzaAZGFW22KVZDfyrYW+QABMrWnJBnSs=
1410
github.com/mrunalp/fileutils v0.5.0 h1:NKzVxiH7eSk+OQ4M+ZYW1K6h27RUV3MI6NUTsHhU6Z4=

specerror/error.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
package specerror
44

55
import (
6+
"errors"
67
"fmt"
78

8-
"github.com/hashicorp/go-multierror"
99
rfc2119 "github.com/opencontainers/runtime-tools/error"
1010
)
1111

@@ -43,7 +43,7 @@ type LevelErrors struct {
4343

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

4949
var ociErrors = map[Code]errorTemplate{}
@@ -107,6 +107,10 @@ func NewError(code Code, err error, version string) error {
107107
}
108108
}
109109

110+
type joinErr interface {
111+
Unwrap() []error
112+
}
113+
110114
// FindError finds an error from a source error (multiple error) and
111115
// returns the error code if found.
112116
// If the source error is nil or empty, return NonError.
@@ -115,16 +119,14 @@ func FindError(err error, code Code) Code {
115119
if err == nil {
116120
return NonError
117121
}
118-
119-
if merr, ok := err.(*multierror.Error); ok {
120-
if merr.ErrorOrNil() == nil {
121-
return NonError
122-
}
123-
for _, e := range merr.Errors {
124-
if rfcErr, ok := e.(*Error); ok {
125-
if rfcErr.Code == code {
126-
return code
127-
}
122+
var rfcErr *Error
123+
if errors.As(err, &rfcErr) && rfcErr.Code == code {
124+
return code
125+
}
126+
if errs, ok := err.(joinErr); ok {
127+
for _, e := range errs.Unwrap() {
128+
if errors.As(e, &rfcErr) && rfcErr.Code == code {
129+
return code
128130
}
129131
}
130132
}
@@ -135,18 +137,18 @@ func FindError(err error, code Code) Code {
135137
// from the source error. If the source error is not a multierror, it
136138
// is returned unchanged.
137139
func SplitLevel(errIn error, level rfc2119.Level) (levelErrors LevelErrors, errOut error) {
138-
merr, ok := errIn.(*multierror.Error)
140+
errs, ok := errIn.(joinErr)
139141
if !ok {
140142
return levelErrors, errIn
141143
}
142-
for _, err := range merr.Errors {
143-
e, ok := err.(*Error)
144-
if ok && e.Err.Level < level {
145-
fmt.Println(e)
146-
levelErrors.Warnings = append(levelErrors.Warnings, e)
144+
for _, err := range errs.Unwrap() {
145+
var rfcErr *Error
146+
if errors.As(err, &rfcErr) && rfcErr.Err.Level < level {
147+
fmt.Println(rfcErr)
148+
levelErrors.Warnings = append(levelErrors.Warnings, rfcErr)
147149
continue
148150
}
149-
levelErrors.Error = multierror.Append(levelErrors.Error, err)
151+
levelErrors.Error = errors.Join(levelErrors.Error, err)
150152
}
151153
return levelErrors, nil
152154
}

0 commit comments

Comments
 (0)