Skip to content

Commit

Permalink
Use errors.Join
Browse files Browse the repository at this point in the history
Replace usages of github.com/joeshaw/multierror with errors.Join,
which was added to the stdlib in Go 1.20.

Closes #216
  • Loading branch information
andrewkroh committed Apr 5, 2024
1 parent 3d71be2 commit 0b615a4
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 18 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.21
require (
github.com/docker/docker v24.0.9+incompatible
github.com/elastic/go-windows v1.0.0
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901
github.com/prometheus/procfs v0.8.0
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.13.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4=
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
Expand Down
4 changes: 1 addition & 3 deletions providers/aix/host_aix_ppc64.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ import (
"strings"
"time"

"github.com/joeshaw/multierror"

"github.com/elastic/go-sysinfo/internal/registry"
"github.com/elastic/go-sysinfo/providers/shared"
"github.com/elastic/go-sysinfo/types"
Expand Down Expand Up @@ -167,7 +165,7 @@ func (r *reader) addErr(err error) bool {

func (r *reader) Err() error {
if len(r.errs) > 0 {
return &multierror.MultiError{Errors: r.errs}
return errors.Join(r.errs...)
}
return nil
}
Expand Down
4 changes: 1 addition & 3 deletions providers/darwin/host_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
"strings"
"time"

"github.com/joeshaw/multierror"

"github.com/elastic/go-sysinfo/internal/registry"
"github.com/elastic/go-sysinfo/providers/shared"
"github.com/elastic/go-sysinfo/types"
Expand Down Expand Up @@ -194,7 +192,7 @@ func (r *reader) addErr(err error) bool {

func (r *reader) Err() error {
if len(r.errs) > 0 {
return &multierror.MultiError{Errors: r.errs}
return errors.Join(r.errs...)
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions providers/linux/host_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"strings"
"time"

"github.com/joeshaw/multierror"
"github.com/prometheus/procfs"

"github.com/elastic/go-sysinfo/internal/registry"
Expand Down Expand Up @@ -185,7 +184,7 @@ func (r *reader) addErr(err error) bool {

func (r *reader) Err() error {
if len(r.errs) > 0 {
return &multierror.MultiError{Errors: r.errs}
return errors.Join(r.errs...)
}
return nil
}
Expand Down
7 changes: 3 additions & 4 deletions providers/linux/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ package linux
import (
"bufio"
"bytes"
"errors"
"fmt"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"

"github.com/joeshaw/multierror"

"github.com/elastic/go-sysinfo/types"
)

Expand Down Expand Up @@ -207,11 +206,11 @@ func makeOSInfo(osRelease map[string]string) (*types.OSInfo, error) {
}

func findDistribRelease(baseDir string) (*types.OSInfo, error) {
var errs []error
matches, err := filepath.Glob(filepath.Join(baseDir, distribRelease))
if err != nil {
return nil, err
}
var errs []error
for _, path := range matches {
if strings.HasSuffix(path, osRelease) || strings.HasSuffix(path, lsbRelease) {
continue
Expand All @@ -229,7 +228,7 @@ func findDistribRelease(baseDir string) (*types.OSInfo, error) {
}
return osInfo, err
}
return nil, fmt.Errorf("no valid /etc/<distrib>-release file found: %w", &multierror.MultiError{Errors: errs})
return nil, fmt.Errorf("no valid /etc/<distrib>-release file found: %w", errors.Join(errs...))
}

func getDistribRelease(file string) (*types.OSInfo, error) {
Expand Down
4 changes: 1 addition & 3 deletions providers/windows/host_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"syscall"
"time"

"github.com/joeshaw/multierror"

stdwindows "golang.org/x/sys/windows"

windows "github.com/elastic/go-windows"
Expand Down Expand Up @@ -129,7 +127,7 @@ func (r *reader) addErr(err error) bool {

func (r *reader) Err() error {
if len(r.errs) > 0 {
return &multierror.MultiError{Errors: r.errs}
return errors.Join(r.errs...)
}
return nil
}
Expand Down

0 comments on commit 0b615a4

Please sign in to comment.