Skip to content
Open
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.21
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/moby/sys/capability v0.4.0
github.com/moby/sys/mountinfo v0.7.2
Expand All @@ -21,7 +20,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/moby/sys/mountinfo v0.7.2 h1:1shs6aH5s4o5H2zQLn796ADW1wMrIwHsyJ2v9KouLrg=
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 @@ type LevelErrors struct {

// 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 @@ func NewError(code Code, err error, version string) error {
}
}

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 @@ func FindError(err error, code Code) Code {
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 @@ func FindError(err error, code Code) Code {
// 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)
}
return levelErrors, nil
}
Loading
Loading