Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use errors.Join #217

Merged
merged 3 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/217.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
Replace usages of github.com/joeshaw/multierror with the stdlib errors.Join(). This may affect the rendering of some error messages.
```
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.21

require (
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 @@ -6,8 +6,6 @@ github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6
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/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
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
9 changes: 4 additions & 5 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 @@ -227,9 +226,9 @@ func findDistribRelease(baseDir string) (*types.OSInfo, error) {
errs = append(errs, fmt.Errorf("in %s: %w", path, err))
continue
}
return osInfo, err
return osInfo, nil
}
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...))
andrewkroh marked this conversation as resolved.
Show resolved Hide resolved
}

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