Skip to content

Commit e858075

Browse files
committed
use multierror in library as well
Signed-off-by: Stephanie <[email protected]>
1 parent 436fb41 commit e858075

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ module github.com/devfile/library
33
go 1.15
44

55
require (
6-
github.com/devfile/api/v2 v2.0.0-20210812170628-ad569a8c7a49
6+
github.com/devfile/api/v2 v2.0.0-20210812215717-9227ef221c84
77
github.com/fatih/color v1.7.0
88
github.com/gobwas/glob v0.2.3
99
github.com/golang/mock v1.5.0
1010
github.com/google/go-cmp v0.5.5
1111
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7
12+
github.com/hashicorp/go-multierror v1.1.1
1213
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348
1314
github.com/mattn/go-colorable v0.1.2 // indirect
1415
github.com/mattn/go-isatty v0.0.12 // indirect

go.sum

+4-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ
8383
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8484
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
8585
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
86-
github.com/devfile/api/v2 v2.0.0-20210812170628-ad569a8c7a49 h1:KXcFl4aAXAgF3Aeu8qm9Ln/Xm4iZ+OtljPBmr1naGzI=
87-
github.com/devfile/api/v2 v2.0.0-20210812170628-ad569a8c7a49/go.mod h1:kLX/nW93gigOHXK3NLeJL2fSS/sgEe+OHu8bo3aoOi4=
86+
github.com/devfile/api/v2 v2.0.0-20210812215717-9227ef221c84 h1:irCNH6Q95HUeUgKctyIbeXGx8fQifC1zdiImasPtUzc=
87+
github.com/devfile/api/v2 v2.0.0-20210812215717-9227ef221c84/go.mod h1:kLX/nW93gigOHXK3NLeJL2fSS/sgEe+OHu8bo3aoOi4=
8888
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
8989
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
9090
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
@@ -225,6 +225,8 @@ github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iP
225225
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
226226
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
227227
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
228+
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
229+
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
228230
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
229231
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
230232
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=

pkg/devfile/validate/validate.go

+9-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
devfileData "github.com/devfile/library/pkg/devfile/parser/data"
77
v2 "github.com/devfile/library/pkg/devfile/parser/data/v2"
88
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"
9-
"strings"
9+
"github.com/hashicorp/go-multierror"
1010
)
1111

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

32-
var errstrings []string
32+
var returnedErr error
3333
switch d := data.(type) {
3434
case *v2.DevfileV2:
3535
// validate components
3636
err = v2Validation.ValidateComponents(components)
3737
if err != nil {
38-
errstrings = append(errstrings, err.Error())
38+
returnedErr = multierror.Append(returnedErr, err)
3939
}
4040

4141
// validate commands
4242
err = v2Validation.ValidateCommands(commands, components)
4343
if err != nil {
44-
errstrings = append(errstrings, err.Error())
44+
returnedErr = multierror.Append(returnedErr, err)
4545
}
4646

4747
err = v2Validation.ValidateEvents(data.GetEvents(), commands)
4848
if err != nil {
49-
errstrings = append(errstrings, err.Error())
49+
returnedErr = multierror.Append(returnedErr, err)
5050
}
5151

5252
err = v2Validation.ValidateProjects(projects)
5353
if err != nil {
54-
errstrings = append(errstrings, err.Error())
54+
returnedErr = multierror.Append(returnedErr, err)
5555
}
5656

5757
err = v2Validation.ValidateStarterProjects(starterProjects)
5858
if err != nil {
59-
errstrings = append(errstrings, err.Error())
59+
returnedErr = multierror.Append(returnedErr, err)
6060
}
6161

62-
if len(errstrings) > 0 {
63-
return fmt.Errorf(strings.Join(errstrings, "\n"))
64-
} else {
65-
return nil
66-
}
62+
return returnedErr
63+
6764
default:
6865
return fmt.Errorf("unknown devfile type %T", d)
6966
}
70-
71-
if len(errstrings) > 0 {
72-
return fmt.Errorf(strings.Join(errstrings, "\n"))
73-
}
74-
75-
return nil
7667
}

0 commit comments

Comments
 (0)