Skip to content

Commit c7a2c6f

Browse files
kruskallericywl
andauthored
refactor: replace pkg/errors with stdlib (#17697)
* refactor: replace pkg/errors with stdlib * lint: fix linter issues * lint: fix linter issues * Revert "lint: fix linter issues" This reverts commit 45d511c. * Revert "lint: fix linter issues" This reverts commit 137972d. * lint: ignore config files --------- Co-authored-by: Eric <[email protected]>
1 parent 5f6d6b3 commit c7a2c6f

37 files changed

+157
-158
lines changed

NOTICE-fips.txt

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,39 +2605,6 @@ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
26052605
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
26062606
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26072607

2608-
--------------------------------------------------------------------------------
2609-
Dependency : github.com/pkg/errors
2610-
Version: v0.9.1
2611-
Licence type (autodetected): BSD-2-Clause
2612-
--------------------------------------------------------------------------------
2613-
2614-
Contents of probable licence file $GOMODCACHE/github.com/pkg/[email protected]/LICENSE:
2615-
2616-
Copyright (c) 2015, Dave Cheney <[email protected]>
2617-
All rights reserved.
2618-
2619-
Redistribution and use in source and binary forms, with or without
2620-
modification, are permitted provided that the following conditions are met:
2621-
2622-
* Redistributions of source code must retain the above copyright notice, this
2623-
list of conditions and the following disclaimer.
2624-
2625-
* Redistributions in binary form must reproduce the above copyright notice,
2626-
this list of conditions and the following disclaimer in the documentation
2627-
and/or other materials provided with the distribution.
2628-
2629-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2630-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2631-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2632-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
2633-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2634-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2635-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
2636-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2637-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2638-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2639-
2640-
26412608
--------------------------------------------------------------------------------
26422609
Dependency : github.com/ryanuber/go-glob
26432610
Version: v1.0.0
@@ -11805,6 +11772,39 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1180511772

1180611773

1180711774

11775+
--------------------------------------------------------------------------------
11776+
Dependency : github.com/pkg/errors
11777+
Version: v0.9.1
11778+
Licence type (autodetected): BSD-2-Clause
11779+
--------------------------------------------------------------------------------
11780+
11781+
Contents of probable licence file $GOMODCACHE/github.com/pkg/[email protected]/LICENSE:
11782+
11783+
Copyright (c) 2015, Dave Cheney <[email protected]>
11784+
All rights reserved.
11785+
11786+
Redistribution and use in source and binary forms, with or without
11787+
modification, are permitted provided that the following conditions are met:
11788+
11789+
* Redistributions of source code must retain the above copyright notice, this
11790+
list of conditions and the following disclaimer.
11791+
11792+
* Redistributions in binary form must reproduce the above copyright notice,
11793+
this list of conditions and the following disclaimer in the documentation
11794+
and/or other materials provided with the distribution.
11795+
11796+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
11797+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
11798+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
11799+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
11800+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
11801+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
11802+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
11803+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
11804+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
11805+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11806+
11807+
1180811808
--------------------------------------------------------------------------------
1180911809
Dependency : github.com/planetscale/vtprotobuf
1181011810
Version: v0.6.1-0.20240319094008-0393e58bdf10

NOTICE.txt

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,39 +2605,6 @@ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
26052605
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
26062606
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26072607

2608-
--------------------------------------------------------------------------------
2609-
Dependency : github.com/pkg/errors
2610-
Version: v0.9.1
2611-
Licence type (autodetected): BSD-2-Clause
2612-
--------------------------------------------------------------------------------
2613-
2614-
Contents of probable licence file $GOMODCACHE/github.com/pkg/[email protected]/LICENSE:
2615-
2616-
Copyright (c) 2015, Dave Cheney <[email protected]>
2617-
All rights reserved.
2618-
2619-
Redistribution and use in source and binary forms, with or without
2620-
modification, are permitted provided that the following conditions are met:
2621-
2622-
* Redistributions of source code must retain the above copyright notice, this
2623-
list of conditions and the following disclaimer.
2624-
2625-
* Redistributions in binary form must reproduce the above copyright notice,
2626-
this list of conditions and the following disclaimer in the documentation
2627-
and/or other materials provided with the distribution.
2628-
2629-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2630-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2631-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2632-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
2633-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2634-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2635-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
2636-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2637-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2638-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2639-
2640-
26412608
--------------------------------------------------------------------------------
26422609
Dependency : github.com/ryanuber/go-glob
26432610
Version: v1.0.0
@@ -13302,6 +13269,39 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1330213269

1330313270

1330413271

13272+
--------------------------------------------------------------------------------
13273+
Dependency : github.com/pkg/errors
13274+
Version: v0.9.1
13275+
Licence type (autodetected): BSD-2-Clause
13276+
--------------------------------------------------------------------------------
13277+
13278+
Contents of probable licence file $GOMODCACHE/github.com/pkg/[email protected]/LICENSE:
13279+
13280+
Copyright (c) 2015, Dave Cheney <[email protected]>
13281+
All rights reserved.
13282+
13283+
Redistribution and use in source and binary forms, with or without
13284+
modification, are permitted provided that the following conditions are met:
13285+
13286+
* Redistributions of source code must retain the above copyright notice, this
13287+
list of conditions and the following disclaimer.
13288+
13289+
* Redistributions in binary form must reproduce the above copyright notice,
13290+
this list of conditions and the following disclaimer in the documentation
13291+
and/or other materials provided with the distribution.
13292+
13293+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
13294+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
13295+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
13296+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
13297+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
13298+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
13299+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
13300+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
13301+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13302+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13303+
13304+
1330513305
--------------------------------------------------------------------------------
1330613306
Dependency : github.com/planetscale/vtprotobuf
1330713307
Version: v0.6.1-0.20240319094008-0393e58bdf10

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ require (
2626
github.com/google/go-cmp v0.7.0
2727
github.com/gorilla/mux v1.8.1
2828
github.com/libp2p/go-reuseport v0.4.0
29-
github.com/pkg/errors v0.9.1
3029
github.com/ryanuber/go-glob v1.0.0
3130
github.com/spf13/cobra v1.9.1
3231
github.com/spf13/pflag v1.0.7
@@ -184,6 +183,7 @@ require (
184183
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
185184
github.com/pierrec/lz4/v4 v4.1.22 // indirect
186185
github.com/pjbgf/sha1cd v0.3.0 // indirect
186+
github.com/pkg/errors v0.9.1 // indirect
187187
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
188188
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
189189
github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect

internal/agentcfg/cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
package agentcfg
1919

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

25-
"github.com/pkg/errors"
2626
"github.com/stretchr/testify/assert"
2727
"github.com/stretchr/testify/require"
2828

internal/agentcfg/elasticsearch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package agentcfg
2020
import (
2121
"context"
2222
"encoding/json"
23+
"errors"
2324
"fmt"
2425
"io"
2526
"net/http"
@@ -28,7 +29,6 @@ import (
2829
"sync/atomic"
2930
"time"
3031

31-
"github.com/pkg/errors"
3232
"go.opentelemetry.io/otel/metric"
3333
"go.opentelemetry.io/otel/trace"
3434

internal/agentcfg/kibana.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ import (
2121
"bytes"
2222
"context"
2323
"encoding/json"
24+
"errors"
25+
"fmt"
2426
"io"
2527
"net/http"
2628
"time"
2729

28-
"github.com/pkg/errors"
29-
3030
"github.com/elastic/elastic-agent-libs/logp"
3131

3232
"github.com/elastic/apm-server/internal/kibana"
@@ -83,7 +83,7 @@ func (f *KibanaFetcher) Fetch(ctx context.Context, query Query) (Result, error)
8383
func (f *KibanaFetcher) request(ctx context.Context, r io.Reader) ([]byte, error) {
8484
resp, err := f.client.Send(ctx, http.MethodPost, endpoint, nil, nil, r)
8585
if err != nil {
86-
return nil, errors.Wrap(err, ErrMsgSendToKibanaFailed)
86+
return nil, fmt.Errorf(ErrMsgSendToKibanaFailed+": %w", err)
8787
}
8888
defer resp.Body.Close()
8989

@@ -93,10 +93,10 @@ func (f *KibanaFetcher) request(ctx context.Context, r io.Reader) ([]byte, error
9393

9494
result, err := io.ReadAll(resp.Body)
9595
if resp.StatusCode >= http.StatusBadRequest {
96-
return nil, errors.Errorf("agentcfg kibana request failed with status code %d: %s", resp.StatusCode, string(result))
96+
return nil, fmt.Errorf("agentcfg kibana request failed with status code %d: %s", resp.StatusCode, string(result))
9797
}
9898
if err != nil {
99-
return nil, errors.Wrap(err, ErrMsgReadKibanaResponse)
99+
return nil, fmt.Errorf(ErrMsgReadKibanaResponse+": %w", err)
100100
}
101101
return result, nil
102102
}

internal/beatcmd/locker.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
package beatcmd
1919

2020
import (
21+
"errors"
22+
"fmt"
2123
"os"
2224

2325
"github.com/gofrs/flock"
24-
"github.com/pkg/errors"
2526

2627
"github.com/elastic/elastic-agent-libs/paths"
2728
)
@@ -30,7 +31,7 @@ var (
3031
// ErrAlreadyLocked is returned when a lock on the data path is attempted but
3132
// unsuccessful because another Beat instance already has the lock on the same
3233
// data path.
33-
ErrAlreadyLocked = errors.New("data path already locked by another beat. Please make sure that multiple beats are not sharing the same data path (path.data).")
34+
ErrAlreadyLocked = errors.New("data path already locked by another beat. Please make sure that multiple beats are not sharing the same data path (path.data)")
3435
)
3536

3637
type locker struct {
@@ -50,7 +51,7 @@ func newLocker(b *Beat) *locker {
5051
func (l *locker) lock() error {
5152
isLocked, err := l.fl.TryLock()
5253
if err != nil {
53-
return errors.Wrap(err, "unable to lock data path")
54+
return fmt.Errorf("unable to lock data path: %w", err)
5455
}
5556

5657
if !isLocked {
@@ -64,12 +65,12 @@ func (l *locker) lock() error {
6465
func (l *locker) unlock() error {
6566
err := l.fl.Unlock()
6667
if err != nil {
67-
return errors.Wrap(err, "unable to unlock data path")
68+
return fmt.Errorf("unable to unlock data path: %w", err)
6869
}
6970

7071
err = os.Remove(l.fl.Path())
7172
if err != nil {
72-
return errors.Wrap(err, "unable to unlock data path")
73+
return fmt.Errorf("unable to unlock data path: %w", err)
7374
}
7475

7576
return nil

internal/beater/api/config/agent/handler.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ package agent
1919

2020
import (
2121
"encoding/json"
22+
"errors"
2223
"fmt"
2324
"net/http"
2425
"strings"
2526
"time"
2627

27-
"github.com/pkg/errors"
28-
2928
"github.com/elastic/apm-server/internal/agentcfg"
3029
"github.com/elastic/apm-server/internal/beater/auth"
3130
"github.com/elastic/apm-server/internal/beater/headers"
@@ -146,9 +145,7 @@ func buildQuery(c *request.Context) (agentcfg.Query, error) {
146145
},
147146
}
148147
default:
149-
if err := errors.Errorf("%s: %s", msgMethodUnsupported, r.Method); err != nil {
150-
return query, err
151-
}
148+
return query, fmt.Errorf("%s: %s", msgMethodUnsupported, r.Method)
152149
}
153150
if query.Service.Name == "" {
154151
return query, errors.New(agentcfg.ServiceName + " is required")

internal/beater/api/config/agent/handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"bytes"
2222
"context"
2323
"encoding/json"
24+
"errors"
2425
"fmt"
2526
"io"
2627
"net/http"
@@ -29,7 +30,6 @@ import (
2930
"testing"
3031
"time"
3132

32-
"github.com/pkg/errors"
3333
"github.com/stretchr/testify/assert"
3434
"github.com/stretchr/testify/require"
3535

internal/beater/api/mux.go

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

2020
import (
21+
"fmt"
2122
"net/http"
2223
httppprof "net/http/pprof"
2324
"regexp"
2425
"runtime/pprof"
2526

2627
"github.com/gorilla/mux"
27-
"github.com/pkg/errors"
2828
"go.opentelemetry.io/otel/metric"
2929
"go.opentelemetry.io/otel/trace"
3030
"go.uber.org/zap"
@@ -210,14 +210,14 @@ func (r *routeBuilder) rumIntakeHandler(mp metric.MeterProvider) func() (request
210210
if r.cfg.RumConfig.LibraryPattern != "" {
211211
re, err := regexp.Compile(r.cfg.RumConfig.LibraryPattern)
212212
if err != nil {
213-
return nil, errors.Wrap(err, "invalid library pattern regex")
213+
return nil, fmt.Errorf("invalid library pattern regex: %w", err)
214214
}
215215
batchProcessors = append(batchProcessors, srvmodelprocessor.SetLibraryFrame{Pattern: re})
216216
}
217217
if r.cfg.RumConfig.ExcludeFromGrouping != "" {
218218
re, err := regexp.Compile(r.cfg.RumConfig.ExcludeFromGrouping)
219219
if err != nil {
220-
return nil, errors.Wrap(err, "invalid exclude from grouping regex")
220+
return nil, fmt.Errorf("invalid exclude from grouping regex: %w", err)
221221
}
222222
batchProcessors = append(batchProcessors, srvmodelprocessor.SetExcludeFromGrouping{Pattern: re})
223223
}

0 commit comments

Comments
 (0)