-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
feat: replace multierror with stdlib errors wrapping #41043
base: main
Are you sure you want to change the base?
Conversation
replace multierror library with stdlib error wrapping
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
|
@kruskall can we also remove the use of "github.com/pkg/errors"? |
Pinging @elastic/sec-windows-platform (Team:Security-Windows Platform) |
Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane) |
Pinging @elastic/sec-linux-platform (Team:Security-Linux Platform) |
This pull request is now in conflicts. Could you fix it? 🙏
|
That's not possible:
|
} | ||
log.Warnf("errors loading rules: %v", errs.Err()) | ||
log.Warnf("errors loading rules: %v", errors.Join(errs...)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Warnf("errors loading rules: %v", errors.Join(errs...)) | |
log.Warnf("errors loading rules: %w", errors.Join(errs...)) |
merr, ok := ucfgErr.Reason().(*multierror.MultiError) | ||
merr, ok := ucfgErr.Reason().(interface { | ||
Unwrap() []error | ||
}) | ||
if !ok { | ||
t.Fatal("expected MultiError") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.Fatal("expected MultiError") | |
t.Fatal("expected slice error unwrapper") |
err.SetKey(convMap.Key + "." + err.Key()) | ||
_, errs := convMap.Schema.ApplyTo(subEvent, subData.(map[string]interface{})) | ||
for _, err := range errs { | ||
var keyErr schema.KeyError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is surprising. It would be made less so if there were a comment explaining that while schema.KeyError
doesn't satisfy error
, its implementations do.
@@ -536,7 +536,7 @@ func TestFieldConcat(t *testing.T) { | |||
{Name: "foo", Fields: Fields{{Name: "b", Fields: Fields{{Name: "c"}}}}}, | |||
}, | |||
|
|||
err: "2 errors: fields contain key <a>; fields contain non object node conflicting with key <foo.b.c>", | |||
err: "fields contain key <a>\nfields contain non object node conflicting with key <foo.b.c>", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering about this. How does this impact on error rendering to users? I suspect it would be and improvement, but it's worth checking.
@@ -136,11 +135,13 @@ func eventMapping(entries []Entry, mapping AttributeMapping) ([]mapstr.M, error) | |||
errs = append(errs, err) | |||
} | |||
case map[string]interface{}: | |||
constructEvents(entryValues, v, mbeanEvents, mapping, errs) | |||
errs = constructEvents(entryValues, v, mbeanEvents, mapping, errs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice incidental fixes.
@@ -106,6 +108,7 @@ func (lo *IPv6Loopback) AddRandomAddress() (addr net.IP, err error) { | |||
if err = unix.Bind(fd, &bindAddr); err == nil { | |||
break | |||
} | |||
//nolint:errorlint // ignore | |||
if errno, ok := err.(unix.Errno); !ok || errno != unix.EADDRNOTAVAIL { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be expressible as if err != unix.EADDRNOTAVAIL {
; syscall.Errno
is an error
so they are comparable. Caveat if someone ever implements an error that is not on a pointer and contains a slice or a map then ¡bang!, but that's true for most uses of errors.
@@ -66,16 +65,16 @@ func (r *Coordinator) Run(ctx context.Context, t telemetry.T) error { | |||
}(ctx, t, rfn) | |||
} | |||
|
|||
// Wait for goroutine to complete and aggregate any errors from the goroutine and | |||
// Wait for goroutine to complete and aggregate any errs from the goroutine and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this line? This is English.
// reloadInputs wraps the multierror so we have to call Unwrap | ||
wr := errors.Unwrap(err) | ||
|
||
//nolint:errorlint // ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is it complaining about here?
// the standard library errors package. | ||
if errors.As(err, &merror) { | ||
for _, err := range merror.Errors { | ||
//nolint:errorlint // There are no new changes to this line but |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finish sentence?
@@ -824,17 +828,17 @@ func (cm *BeatV2Manager) reloadInputs(inputUnits []*agentUnit) error { | |||
} | |||
|
|||
if err := obj.Reload(inputBeatCfgs); err != nil { | |||
merror := &multierror.MultiError{} | |||
realErrors := multierror.Errors{} | |||
var realErrors []error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/realErrors/errs/g
?
Proposed commit message
replace multierror library with stdlib error wrapping
Go 1.20 added errors.Join allowing for multierrors. Replace go-multierror usage with native go errors
Checklist
CHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.Disruptive User Impact
Author's Checklist
How to test this PR locally
Related issues
Use cases
Screenshots
Logs