Skip to content

Commit

Permalink
Merge pull request #113 from yangcao77/577-use-multierrors-in-library
Browse files Browse the repository at this point in the history
use multierror in library
  • Loading branch information
yangcao77 authored Aug 16, 2021
2 parents 436fb41 + e858075 commit c4ec946
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ module github.com/devfile/library
go 1.15

require (
github.com/devfile/api/v2 v2.0.0-20210812170628-ad569a8c7a49
github.com/devfile/api/v2 v2.0.0-20210812215717-9227ef221c84
github.com/fatih/color v1.7.0
github.com/gobwas/glob v0.2.3
github.com/golang/mock v1.5.0
github.com/google/go-cmp v0.5.5
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7
github.com/hashicorp/go-multierror v1.1.1
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/devfile/api/v2 v2.0.0-20210812170628-ad569a8c7a49 h1:KXcFl4aAXAgF3Aeu8qm9Ln/Xm4iZ+OtljPBmr1naGzI=
github.com/devfile/api/v2 v2.0.0-20210812170628-ad569a8c7a49/go.mod h1:kLX/nW93gigOHXK3NLeJL2fSS/sgEe+OHu8bo3aoOi4=
github.com/devfile/api/v2 v2.0.0-20210812215717-9227ef221c84 h1:irCNH6Q95HUeUgKctyIbeXGx8fQifC1zdiImasPtUzc=
github.com/devfile/api/v2 v2.0.0-20210812215717-9227ef221c84/go.mod h1:kLX/nW93gigOHXK3NLeJL2fSS/sgEe+OHu8bo3aoOi4=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
Expand Down Expand Up @@ -225,6 +225,8 @@ github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iP
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
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/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
Expand Down
27 changes: 9 additions & 18 deletions pkg/devfile/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
devfileData "github.com/devfile/library/pkg/devfile/parser/data"
v2 "github.com/devfile/library/pkg/devfile/parser/data/v2"
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"
"strings"
"github.com/hashicorp/go-multierror"
)

// ValidateDevfileData validates whether sections of devfile are compatible
Expand All @@ -29,48 +29,39 @@ func ValidateDevfileData(data devfileData.DevfileData) error {
return err
}

var errstrings []string
var returnedErr error
switch d := data.(type) {
case *v2.DevfileV2:
// validate components
err = v2Validation.ValidateComponents(components)
if err != nil {
errstrings = append(errstrings, err.Error())
returnedErr = multierror.Append(returnedErr, err)
}

// validate commands
err = v2Validation.ValidateCommands(commands, components)
if err != nil {
errstrings = append(errstrings, err.Error())
returnedErr = multierror.Append(returnedErr, err)
}

err = v2Validation.ValidateEvents(data.GetEvents(), commands)
if err != nil {
errstrings = append(errstrings, err.Error())
returnedErr = multierror.Append(returnedErr, err)
}

err = v2Validation.ValidateProjects(projects)
if err != nil {
errstrings = append(errstrings, err.Error())
returnedErr = multierror.Append(returnedErr, err)
}

err = v2Validation.ValidateStarterProjects(starterProjects)
if err != nil {
errstrings = append(errstrings, err.Error())
returnedErr = multierror.Append(returnedErr, err)
}

if len(errstrings) > 0 {
return fmt.Errorf(strings.Join(errstrings, "\n"))
} else {
return nil
}
return returnedErr

default:
return fmt.Errorf("unknown devfile type %T", d)
}

if len(errstrings) > 0 {
return fmt.Errorf(strings.Join(errstrings, "\n"))
}

return nil
}

0 comments on commit c4ec946

Please sign in to comment.