Skip to content

Commit

Permalink
Return all user not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
kitagry committed Jan 17, 2023
1 parent 75acdd3 commit 164be5b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/impl/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/pkg/errors"
"go.uber.org/multierr"
)

func AddCmd(client redashClient, users, groups []string) error {
Expand All @@ -17,14 +18,20 @@ func AddCmd(client redashClient, users, groups []string) error {
}

userIds := make([]int, len(users))
var errs []error
for i, u := range users {
id, err := findUserID(client, u)
if err != nil {
return errors.Wrap(err, "findUserID")
errs = append(errs, errors.Wrap(err, "findUserID"))
continue
}
userIds[i] = id
}

if len(errs) > 0 {
return multierr.Combine(errs...)
}

for i, g := range groupIds {
for j, u := range userIds {
_, err := client.AddMember(g, u)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.10.1
github.com/stretchr/testify v1.7.1
go.uber.org/multierr v1.6.0
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down

0 comments on commit 164be5b

Please sign in to comment.