Skip to content

Commit

Permalink
Use stdlib errors.Join instead of go-multierror
Browse files Browse the repository at this point in the history
Use error wrapping from the errors standard library package instead of
the 3rd party go-multierror package to join multiple errors.

Signed-off-by: Tobias Klauser <[email protected]>
  • Loading branch information
tklauser authored and kkourt committed Nov 27, 2023
1 parent 40a9124 commit de55dde
Show file tree
Hide file tree
Showing 18 changed files with 10 additions and 1,486 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module github.com/cilium/little-vm-helper

go 1.18
go 1.20

require (
github.com/go-git/go-git/v5 v5.10.0
github.com/hashicorp/go-multierror v1.1.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.4
Expand All @@ -23,7 +22,6 @@ require (
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ github.com/go-git/go-git/v5 v5.10.0/go.mod h1:1FOZ/pQnqw24ghP2n7cunVl0ON55BsjPYv
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.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/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
Expand Down
10 changes: 5 additions & 5 deletions pkg/kernels/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ package kernels
import (
"bufio"
"context"
"errors"
"fmt"
"os"
"path/filepath"
"regexp"
"runtime"

"github.com/cilium/little-vm-helper/pkg/logcmd"
"github.com/hashicorp/go-multierror"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -109,8 +109,9 @@ func kcfonfigValidate(opts []ConfigOption) error {
optMap[opt] = mapVal

if mapVal.enabled != optEnabled {
err := fmt.Errorf("value %s misconfigured: expected: %t but seems to be %t based on '%s'", opt, mapVal.enabled, optEnabled, txt)
ret = multierror.Append(ret, err)
ret = errors.Join(ret,
fmt.Errorf("value %s misconfigured: expected: %t but seems to be %t based on '%s'",
opt, mapVal.enabled, optEnabled, txt))
}

}
Expand All @@ -121,8 +122,7 @@ func kcfonfigValidate(opts []ConfigOption) error {

for i, v := range optMap {
if v.enabled && !v.checked {
err := fmt.Errorf("value %s enabled but not found", i)
ret = multierror.Append(ret, err)
ret = errors.Join(ret, fmt.Errorf("value %s enabled but not found", i))
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/kernels/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ package kernels

import (
"context"
"errors"
"fmt"
"os"
"path/filepath"

"github.com/cilium/little-vm-helper/pkg/logcmd"

"github.com/hashicorp/go-multierror"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -116,7 +116,7 @@ func gitRemoveWorkdir(ctx context.Context, log logrus.FieldLogger, arg *gitRemov
arg.workDir,
}
if err := logcmd.RunAndLogCommandContext(ctx, log, GitBinary, worktreeRemoveArgs...); err != nil {
multierror.Append(res, fmt.Errorf("did not remove worktree: %w", err))
res = errors.Join(res, fmt.Errorf("did not remove worktree: %w", err))
}

remoteRemoveArgs := []string{
Expand All @@ -125,7 +125,7 @@ func gitRemoveWorkdir(ctx context.Context, log logrus.FieldLogger, arg *gitRemov
arg.remoteName,
}
if err := logcmd.RunAndLogCommandContext(ctx, log, GitBinary, remoteRemoveArgs...); err != nil {
multierror.Append(res, fmt.Errorf("did not remove remote: %w", err))
res = errors.Join(res, fmt.Errorf("did not remove remote: %w", err))
}

branchRemoveArgs := []string{
Expand All @@ -134,7 +134,7 @@ func gitRemoveWorkdir(ctx context.Context, log logrus.FieldLogger, arg *gitRemov
arg.localBranch,
}
if err := logcmd.RunAndLogCommandContext(ctx, log, GitBinary, branchRemoveArgs...); err != nil {
multierror.Append(res, fmt.Errorf("did not remove local branch: %w", err))
res = errors.Join(res, fmt.Errorf("did not remove local branch: %w", err))
}

return res
Expand Down
Loading

0 comments on commit de55dde

Please sign in to comment.