Skip to content

Commit

Permalink
Use Go 1.20 wrapped errors instead of multierror
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Kitt <[email protected]>
  • Loading branch information
skitt committed Jan 5, 2024
1 parent 14d354b commit e555d8b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.17.x, 1.18.x]
go-version: [1.20.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -24,7 +24,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.18.x
go-version: 1.20.x
- name: Checkout
uses: actions/checkout@v3
- name: Lint
Expand Down
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/uw-labs/lichen

go 1.18
go 1.20

require (
github.com/google/licenseclassifier v0.0.0-20201113175434-78a70215ca36
github.com/hashicorp/go-multierror v1.1.1
github.com/muesli/termenv v0.11.0
github.com/stretchr/testify v1.7.1
github.com/urfave/cli/v2 v2.4.0
Expand All @@ -14,7 +13,6 @@ require (
require (
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/licenseclassifier v0.0.0-20201113175434-78a70215ca36 h1:YGB3wNLUTvq+lbIwdNRsaMJvoX4mCKkwzHlmlT1V+ow=
github.com/google/licenseclassifier v0.0.0-20201113175434-78a70215ca36/go.mod h1:qsqn2hxC+vURpyBRygGUuinTO42MFRLcsmQ/P8v94+M=
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/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
Expand Down
9 changes: 5 additions & 4 deletions internal/module/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package module

import (
"context"
"errors"
"fmt"
"os"
"os/exec"

"github.com/hashicorp/go-multierror"
"github.com/uw-labs/lichen/internal/buildinfo"
"github.com/uw-labs/lichen/internal/model"
)
Expand All @@ -29,17 +29,18 @@ func Extract(ctx context.Context, paths ...string) ([]model.BuildInfo, error) {
}

// verifyExtracted ensures all paths requests are covered by the parsed output
func verifyExtracted(extracted []model.BuildInfo, requested []string) (err error) {
func verifyExtracted(extracted []model.BuildInfo, requested []string) error {
buildInfos := make(map[string]struct{}, len(extracted))
errs := []error{}
for _, binary := range extracted {
buildInfos[binary.Path] = struct{}{}
}
for _, path := range requested {
if _, found := buildInfos[path]; !found {
err = multierror.Append(err, fmt.Errorf("modules could not be obtained from %[1]s (hint: run `go version -m %[1]q`)", path))
errs = append(errs, fmt.Errorf("modules could not be obtained from %[1]s (hint: run `go version -m %[1]q`)", path))
}
}
return
return errors.Join(errs...)
}

// goVersion runs `go version -m [paths ...]` and returns the output
Expand Down
8 changes: 4 additions & 4 deletions internal/module/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os"
"os/exec"

"github.com/hashicorp/go-multierror"
"github.com/uw-labs/lichen/internal/model"
)

Expand Down Expand Up @@ -75,15 +74,16 @@ func Fetch(ctx context.Context, refs []model.ModuleReference) ([]model.Module, e
return modules, nil
}

func verifyFetched(fetched []model.Module, requested []model.ModuleReference) (err error) {
func verifyFetched(fetched []model.Module, requested []model.ModuleReference) error {
fetchedRefs := make(map[model.ModuleReference]struct{}, len(fetched))
errs := []error{}
for _, module := range fetched {
fetchedRefs[module.ModuleReference] = struct{}{}
}
for _, ref := range requested {
if _, found := fetchedRefs[ref]; !found {
err = multierror.Append(err, fmt.Errorf("module %s could not be resolved", ref))
errs = append(errs, fmt.Errorf("module %s could not be resolved", ref))
}
}
return
return errors.Join(errs...)
}
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path/filepath"
"text/template"

"github.com/hashicorp/go-multierror"
"github.com/muesli/termenv"
"github.com/urfave/cli/v2"
"github.com/uw-labs/lichen/internal/scan"
Expand Down Expand Up @@ -88,13 +87,13 @@ func run(c *cli.Context) error {
return fmt.Errorf("failed to write results: %w", err)
}

var rErr error
errs := []error{}
for _, m := range summary.Modules {
if !m.Allowed() {
rErr = multierror.Append(rErr, fmt.Errorf("%s: %s", m.Module.ModuleReference, m.ExplainDecision()))
errs = append(errs, fmt.Errorf("%s: %s", m.Module.ModuleReference, m.ExplainDecision()))
}
}
return rErr
return errors.Join(errs...)
}

func parseConfig(path string) (scan.Config, error) {
Expand Down

0 comments on commit e555d8b

Please sign in to comment.