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

refactor: replace urso/sderr with stdlib errors #39839

Merged
merged 5 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
422 changes: 211 additions & 211 deletions NOTICE.txt

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions filebeat/input/filestream/copytruncate_prospector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
package filestream

import (
"errors"
"fmt"
"os"
"regexp"
"sort"
"strconv"
"time"

"github.com/urso/sderr"

loginp "github.com/elastic/beats/v7/filebeat/input/filestream/internal/input-logfile"
input "github.com/elastic/beats/v7/filebeat/input/v2"
"github.com/elastic/beats/v7/libbeat/common/file"
Expand Down Expand Up @@ -230,7 +230,7 @@ func (p *copyTruncateFileProspector) Run(ctx input.Context, s loginp.StateMetada

errs := tg.Wait()
if len(errs) > 0 {
log.Error("%s", sderr.WrapAll(errs, "running prospector failed"))
log.Error("%s", fmt.Errorf("running prospector failed: %w", errors.Join(errs...)))
kruskall marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
"sync"
"time"

"github.com/urso/sderr"

"github.com/elastic/go-concert/unison"

v2 "github.com/elastic/beats/v7/filebeat/input/v2"
Expand Down Expand Up @@ -141,7 +139,7 @@ func (cim *InputManager) Init(group unison.Group) error {
if err != nil {
store.Release()
cim.shutdown()
return sderr.Wrap(err, "Can not start registry cleanup process")
return fmt.Errorf("Can not start registry cleanup process: %w", err)
}

return nil
Expand Down
5 changes: 2 additions & 3 deletions filebeat/input/filestream/prospector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
package filestream

import (
"errors"
"fmt"
"time"

"github.com/urso/sderr"

loginp "github.com/elastic/beats/v7/filebeat/input/filestream/internal/input-logfile"
input "github.com/elastic/beats/v7/filebeat/input/v2"
"github.com/elastic/beats/v7/libbeat/beat"
Expand Down Expand Up @@ -160,7 +159,7 @@ func (p *fileProspector) Run(ctx input.Context, s loginp.StateMetadataUpdater, h

errs := tg.Wait()
if len(errs) > 0 {
log.Error("%s", sderr.WrapAll(errs, "running prospector failed"))
log.Error("%s", fmt.Errorf("running prospector failed: %w", errors.Join(errs...)))
}
}

Expand Down
4 changes: 2 additions & 2 deletions filebeat/input/journald/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
package journald

import (
"fmt"
"time"

"github.com/coreos/go-systemd/v22/sdjournal"
"github.com/urso/sderr"

"github.com/elastic/beats/v7/filebeat/input/journald/pkg/journalfield"
"github.com/elastic/beats/v7/filebeat/input/journald/pkg/journalread"
Expand Down Expand Up @@ -181,7 +181,7 @@ func (inp *journald) open(log *logp.Logger, canceler input.Canceler, src cursor.
withTransports(inp.Transports),
withSyslogIdentifiers(inp.Identifiers))
if err != nil {
return nil, sderr.Wrap(err, "failed to create reader for %{path} journal", src.Name())
return nil, fmt.Errorf("failed to create reader for %s journal: %w", src.Name(), err)
}

return reader, nil
Expand Down
9 changes: 4 additions & 5 deletions filebeat/input/journald/pkg/journalread/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"syscall"
"time"

"github.com/coreos/go-systemd/v22/sdjournal"

Check failure on line 29 in filebeat/input/journald/pkg/journalread/reader.go

View workflow job for this annotation

GitHub Actions / lint (linux)

could not import github.com/coreos/go-systemd/v22/sdjournal (-: # github.com/coreos/go-systemd/v22/sdjournal
"github.com/urso/sderr"

"github.com/elastic/beats/v7/libbeat/common/backoff"
"github.com/elastic/beats/v7/libbeat/common/cleanup"
Expand Down Expand Up @@ -96,27 +95,27 @@
if path == localSystemJournalID || path == "" {
j, err := sdjournal.NewJournal()
if err != nil {
err = sderr.Wrap(err, "failed to open local journal")
err = fmt.Errorf("failed to open local journal: %w", err)
}
return j, err
}

stat, err := os.Stat(path)
if err != nil {
return nil, sderr.Wrap(err, "failed to read meta data for %{path}", path)
return nil, fmt.Errorf("failed to read meta data for %s: %w", path, err)
}

if stat.IsDir() {
j, err := sdjournal.NewJournalFromDir(path)
if err != nil {
err = sderr.Wrap(err, "failed to open journal directory %{path}", path)
err = fmt.Errorf("failed to open journal directory %s: %w", path, err)
}
return j, err
}

j, err := sdjournal.NewJournalFromFiles(path)
if err != nil {
err = sderr.Wrap(err, "failed to open journal file %{path}", path)
err = fmt.Errorf("failed to open journal file %s: %w", path, err)
}
return j, err
}
Expand Down
7 changes: 3 additions & 4 deletions filebeat/input/v2/input-cursor/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ package cursor

import (
"context"
"errors"
"fmt"
"runtime/debug"
"time"

"github.com/urso/sderr"

"github.com/elastic/go-concert/ctxtool"
"github.com/elastic/go-concert/unison"

Expand Down Expand Up @@ -81,7 +80,7 @@ func (inp *managedInput) Test(ctx input.TestContext) error {

errs := grp.Wait()
if len(errs) > 0 {
return sderr.WrapAll(errs, "input tests failed")
return fmt.Errorf("input tests failed: %w", errors.Join(errs...))
}
return nil
}
Expand Down Expand Up @@ -127,7 +126,7 @@ func (inp *managedInput) Run(
}

if errs := grp.Wait(); len(errs) > 0 {
return sderr.WrapAll(errs, "input %{id} failed", ctx.ID)
return fmt.Errorf("input %s failed: %w", ctx.ID, errors.Join(errs...))
}
return nil
}
Expand Down
5 changes: 2 additions & 3 deletions filebeat/input/v2/input-cursor/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ package cursor
import (
"context"
"errors"
"fmt"
"sync"
"time"

"github.com/urso/sderr"

"github.com/elastic/go-concert/unison"

v2 "github.com/elastic/beats/v7/filebeat/input/v2"
Expand Down Expand Up @@ -131,7 +130,7 @@ func (cim *InputManager) Init(group unison.Group) error {
if err != nil {
store.Release()
cim.shutdown()
return sderr.Wrap(err, "Can not start registry cleanup process")
return fmt.Errorf("Can not start registry cleanup process: %w", err)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ require (
github.com/stretchr/testify v1.9.0
github.com/tsg/go-daemon v0.0.0-20200207173439-e704b93fd89b
github.com/ugorji/go/codec v1.1.8
github.com/urso/sderr v0.0.0-20210525210834-52b04e8f5c71
github.com/urso/sderr v0.0.0-20210525210834-52b04e8f5c71 // indirect
Copy link
Contributor

Choose a reason for hiding this comment

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

Does go mod why explain why this is still here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, see the PR descrition:

can be dropped completely from the dep graph once elastic/go-concert#69 is merged

github.com/vmware/govmomi v0.0.0-20170802214208-2cad15190b41
github.com/xdg/scram v1.0.3
go.elastic.co/ecszap v1.0.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/google/uuid"
"github.com/urso/sderr"

"github.com/elastic/beats/v7/x-pack/filebeat/input/entityanalytics/internal/collections"
"github.com/elastic/beats/v7/x-pack/filebeat/input/entityanalytics/internal/kvstore"
Expand Down Expand Up @@ -176,7 +175,7 @@ func (s *stateStore) close(commit bool) (err error) {
}

if err != nil {
err = sderr.WrapAll([]error{err, rollbackErr}, "multiple errors during statestore close")
err = fmt.Errorf("multiple errors during statestore close: %w", errors.Join(err, rollbackErr))
} else {
err = rollbackErr
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"fmt"
"time"

"github.com/urso/sderr"

"github.com/elastic/beats/v7/x-pack/filebeat/input/entityanalytics/internal/kvstore"
"github.com/elastic/beats/v7/x-pack/filebeat/input/entityanalytics/provider/okta/internal/okta"
)
Expand Down Expand Up @@ -188,9 +186,7 @@ func (s *stateStore) close(commit bool) (err error) {
}
rollbackErr := s.tx.Rollback()
if rollbackErr == nil {
// FIXME: Use fmt.Errorf("multiple errors during statestore close: %w", errors.Join(err, rollbackErr))
// when go1.20 is supported.
err = sderr.WrapAll([]error{err, rollbackErr}, "multiple errors during statestore close")
err = fmt.Errorf("multiple errors during statestore close: %w", errors.Join(err, rollbackErr))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the to include rollbackErr in theerrors.Join here? We know rollbackErr == nil so won't it just get discarded?

Copy link
Member Author

Choose a reason for hiding this comment

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

It will and I'm honestly confused as well since that's what the previous code was doing 😅

Copy link
Contributor

@efd6 efd6 Jun 10, 2024

Choose a reason for hiding this comment

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

It can just be done non-conditionally. I don't know what I was thinking.

		err = fmt.Errorf("multiple errors during statestore close: %w", errors.Join(err, s.tx.Rollback()))

}
}()

Expand Down
Loading