Skip to content

Commit 3c9f4d9

Browse files
authored
refactor: replace urso/sderr with stdlib errors (#39839)
* refactor: replace urso/sderr with stdlib errors Go 1.20 added multiple errors wrapping so we can migrate to stdlib errors and drop the additional dependency on github.com/urso/sderr * refactor: avoid wrapping and unwrapping * Update copytruncate_prospector.go * Update statestore.go
1 parent 1fd65c7 commit 3c9f4d9

File tree

11 files changed

+231
-243
lines changed

11 files changed

+231
-243
lines changed

NOTICE.txt

Lines changed: 211 additions & 211 deletions
Large diffs are not rendered by default.

filebeat/input/filestream/copytruncate_prospector.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818
package filestream
1919

2020
import (
21+
"errors"
2122
"os"
2223
"regexp"
2324
"sort"
2425
"strconv"
2526
"time"
2627

27-
"github.com/urso/sderr"
28-
2928
loginp "github.com/elastic/beats/v7/filebeat/input/filestream/internal/input-logfile"
3029
input "github.com/elastic/beats/v7/filebeat/input/v2"
3130
"github.com/elastic/beats/v7/libbeat/common/file"
@@ -230,7 +229,7 @@ func (p *copyTruncateFileProspector) Run(ctx input.Context, s loginp.StateMetada
230229

231230
errs := tg.Wait()
232231
if len(errs) > 0 {
233-
log.Error("%s", sderr.WrapAll(errs, "running prospector failed"))
232+
log.Errorf("running prospector failed: %v", errors.Join(errs...))
234233
}
235234
}
236235

filebeat/input/filestream/internal/input-logfile/manager.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import (
2525
"sync"
2626
"time"
2727

28-
"github.com/urso/sderr"
29-
3028
"github.com/elastic/go-concert/unison"
3129

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

147145
return nil

filebeat/input/filestream/prospector.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
package filestream
1919

2020
import (
21+
"errors"
2122
"fmt"
2223
"time"
2324

24-
"github.com/urso/sderr"
25-
2625
loginp "github.com/elastic/beats/v7/filebeat/input/filestream/internal/input-logfile"
2726
input "github.com/elastic/beats/v7/filebeat/input/v2"
2827
"github.com/elastic/beats/v7/libbeat/beat"
@@ -160,7 +159,7 @@ func (p *fileProspector) Run(ctx input.Context, s loginp.StateMetadataUpdater, h
160159

161160
errs := tg.Wait()
162161
if len(errs) > 0 {
163-
log.Error("%s", sderr.WrapAll(errs, "running prospector failed"))
162+
log.Errorf("running prospector failed: %v", errors.Join(errs...))
164163
}
165164
}
166165

filebeat/input/journald/input.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
package journald
2121

2222
import (
23+
"fmt"
2324
"time"
2425

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

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

187187
return reader, nil

filebeat/input/journald/pkg/journalread/reader.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"time"
2828

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

3231
"github.com/elastic/beats/v7/libbeat/common/backoff"
3332
"github.com/elastic/beats/v7/libbeat/common/cleanup"
@@ -96,27 +95,27 @@ func openJournal(path string) (*sdjournal.Journal, error) {
9695
if path == localSystemJournalID || path == "" {
9796
j, err := sdjournal.NewJournal()
9897
if err != nil {
99-
err = sderr.Wrap(err, "failed to open local journal")
98+
err = fmt.Errorf("failed to open local journal: %w", err)
10099
}
101100
return j, err
102101
}
103102

104103
stat, err := os.Stat(path)
105104
if err != nil {
106-
return nil, sderr.Wrap(err, "failed to read meta data for %{path}", path)
105+
return nil, fmt.Errorf("failed to read meta data for %s: %w", path, err)
107106
}
108107

109108
if stat.IsDir() {
110109
j, err := sdjournal.NewJournalFromDir(path)
111110
if err != nil {
112-
err = sderr.Wrap(err, "failed to open journal directory %{path}", path)
111+
err = fmt.Errorf("failed to open journal directory %s: %w", path, err)
113112
}
114113
return j, err
115114
}
116115

117116
j, err := sdjournal.NewJournalFromFiles(path)
118117
if err != nil {
119-
err = sderr.Wrap(err, "failed to open journal file %{path}", path)
118+
err = fmt.Errorf("failed to open journal file %s: %w", path, err)
120119
}
121120
return j, err
122121
}

filebeat/input/v2/input-cursor/input.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ package cursor
1919

2020
import (
2121
"context"
22+
"errors"
2223
"fmt"
2324
"runtime/debug"
2425
"time"
2526

26-
"github.com/urso/sderr"
27-
2827
"github.com/elastic/go-concert/ctxtool"
2928
"github.com/elastic/go-concert/unison"
3029

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

8281
errs := grp.Wait()
8382
if len(errs) > 0 {
84-
return sderr.WrapAll(errs, "input tests failed")
83+
return fmt.Errorf("input tests failed: %w", errors.Join(errs...))
8584
}
8685
return nil
8786
}
@@ -127,7 +126,7 @@ func (inp *managedInput) Run(
127126
}
128127

129128
if errs := grp.Wait(); len(errs) > 0 {
130-
return sderr.WrapAll(errs, "input %{id} failed", ctx.ID)
129+
return fmt.Errorf("input %s failed: %w", ctx.ID, errors.Join(errs...))
131130
}
132131
return nil
133132
}

filebeat/input/v2/input-cursor/manager.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ package cursor
2020
import (
2121
"context"
2222
"errors"
23+
"fmt"
2324
"sync"
2425
"time"
2526

26-
"github.com/urso/sderr"
27-
2827
"github.com/elastic/go-concert/unison"
2928

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

137136
return nil

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ require (
144144
github.com/stretchr/testify v1.9.0
145145
github.com/tsg/go-daemon v0.0.0-20200207173439-e704b93fd89b
146146
github.com/ugorji/go/codec v1.1.8
147-
github.com/urso/sderr v0.0.0-20210525210834-52b04e8f5c71
147+
github.com/urso/sderr v0.0.0-20210525210834-52b04e8f5c71 // indirect
148148
github.com/vmware/govmomi v0.0.0-20170802214208-2cad15190b41
149149
github.com/xdg/scram v1.0.3
150150
go.elastic.co/ecszap v1.0.2

x-pack/filebeat/input/entityanalytics/provider/azuread/statestore.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"time"
1212

1313
"github.com/google/uuid"
14-
"github.com/urso/sderr"
1514

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

178177
if err != nil {
179-
err = sderr.WrapAll([]error{err, rollbackErr}, "multiple errors during statestore close")
178+
err = fmt.Errorf("multiple errors during statestore close: %w", errors.Join(err, rollbackErr))
180179
} else {
181180
err = rollbackErr
182181
}

0 commit comments

Comments
 (0)