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

feat: replace multierror with stdlib errors wrapping #41043

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

kruskall
Copy link
Member

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

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Disruptive User Impact

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

replace multierror library with stdlib error wrapping
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Sep 29, 2024
Copy link
Contributor

mergify bot commented Sep 29, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @kruskall? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit

Copy link
Contributor

mergify bot commented Sep 29, 2024

backport-8.x has been added to help with the transition to the new branch 8.x.
If you don't need it please use backport-skip label and remove the backport-8.x label.

@mergify mergify bot added the backport-8.x Automated backport to the 8.x branch with mergify label Sep 29, 2024
@kruskall kruskall marked this pull request as ready for review September 30, 2024 09:43
@kruskall kruskall requested review from a team as code owners September 30, 2024 09:43
@shmsr
Copy link
Member

shmsr commented Sep 30, 2024

@kruskall can we also remove the use of "github.com/pkg/errors"?

@pierrehilbert pierrehilbert added Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team Team:Security-Linux Platform Linux Platform Team in Security Solution Team:Security-Windows Platform Windows Platform Team in Security Solution Team:Monitoring Stack Monitoring team labels Sep 30, 2024
@elasticmachine
Copy link
Collaborator

Pinging @elastic/sec-windows-platform (Team:Security-Windows Platform)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/sec-linux-platform (Team:Security-Linux Platform)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Sep 30, 2024
Copy link
Contributor

mergify bot commented Sep 30, 2024

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b feat/drop-multierror upstream/feat/drop-multierror
git merge upstream/main
git push upstream feat/drop-multierror

@kruskall
Copy link
Member Author

@kruskall can we also remove the use of "github.com/pkg/errors"?

That's not possible:

"github.com/pkg/errors" //nolint:gomodguard // go-cfclient uses pkg/errors internally, must be upgraded to at least https:/cloudfoundry-community/go-cfclient/commit/0ada4e9452

auditbeat/module/auditd/config.go Show resolved Hide resolved
auditbeat/module/file_integrity/config_test.go Outdated Show resolved Hide resolved
err.SetKey(convMap.Key + "." + err.Key())
_, errs := convMap.Schema.ApplyTo(subEvent, subData.(map[string]interface{}))
for _, err := range errs {
var keyErr schema.KeyError
Copy link
Contributor

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>",
Copy link
Contributor

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.

metricbeat/module/jolokia/jmx/data.go Show resolved Hide resolved
x-pack/auditbeat/module/system/socket/helper/loopback.go Outdated Show resolved Hide resolved
x-pack/functionbeat/function/core/coordinator.go Outdated Show resolved Hide resolved
// reloadInputs wraps the multierror so we have to call Unwrap
wr := errors.Unwrap(err)

//nolint:errorlint // ignore
Copy link
Contributor

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?

x-pack/libbeat/management/managerV2.go Outdated Show resolved Hide resolved
x-pack/libbeat/management/managerV2.go Outdated Show resolved Hide resolved
@@ -108,8 +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 {
if !errors.Is(err, unix.EADDRNOTAVAIL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:old-man-shouting-at-clouds: x/sys/unix has two instances of %w (both in code generators rather than lib code) and AFAICS no other form of error wrapping (it would be very strange if a package that sits at this level of the stack did). While not bound by go1compat or semver, it would be extremely surprising if this ever changed since code is copied from x/sys/unix into the std tree. But if it keeps people happy…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.x Automated backport to the 8.x branch with mergify enhancement Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team Team:Monitoring Stack Monitoring team Team:Security-Linux Platform Linux Platform Team in Security Solution Team:Security-Windows Platform Windows Platform Team in Security Solution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants