lint: github.com/pkg/errors -> errors (#3091)

This commit is contained in:
mmetc 2024-06-21 14:31:45 +02:00 committed by GitHub
parent 4b988701ed
commit 0e93f98cad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 18 deletions

View file

@ -52,8 +52,6 @@ linters-settings:
desc: "errors.Wrap() is deprecated in favor of fmt.Errorf()"
files:
- "!**/pkg/database/*.go"
- "!**/pkg/exprhelpers/*.go"
- "!**/pkg/acquisition/modules/appsec/appsec.go"
- "!**/pkg/apiserver/controllers/v1/errors.go"
yaml:
files:

View file

@ -17,7 +17,6 @@ import (
"github.com/crowdsecurity/crowdsec/pkg/types"
"github.com/crowdsecurity/go-cs-lib/trace"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
"gopkg.in/tomb.v2"
@ -98,7 +97,7 @@ func (w *AppsecSource) UnmarshalConfig(yamlConfig []byte) error {
err := yaml.UnmarshalStrict(yamlConfig, &w.config)
if err != nil {
return errors.Wrap(err, "Cannot parse appsec configuration")
return fmt.Errorf("Cannot parse appsec configuration: %w", err)
}
if w.config.ListenAddr == "" && w.config.ListenSocket == "" {
@ -153,7 +152,7 @@ func (w *AppsecSource) GetAggregMetrics() []prometheus.Collector {
func (w *AppsecSource) Configure(yamlConfig []byte, logger *log.Entry, MetricsLevel int) error {
err := w.UnmarshalConfig(yamlConfig)
if err != nil {
return errors.Wrap(err, "unable to parse appsec configuration")
return fmt.Errorf("unable to parse appsec configuration: %w", err)
}
w.logger = logger
w.metricsLevel = MetricsLevel
@ -263,7 +262,7 @@ func (w *AppsecSource) StreamingAcquisition(out chan types.Event, t *tomb.Tomb)
_ = os.RemoveAll(w.config.ListenSocket)
listener, err := net.Listen("unix", w.config.ListenSocket)
if err != nil {
return errors.Wrap(err, "Appsec server failed")
return fmt.Errorf("Appsec server failed: %w", err)
}
defer listener.Close()
if w.config.CertFilePath != "" && w.config.KeyFilePath != "" {
@ -272,7 +271,7 @@ func (w *AppsecSource) StreamingAcquisition(out chan types.Event, t *tomb.Tomb)
err = w.server.Serve(listener)
}
if err != nil && err != http.ErrServerClosed {
return errors.Wrap(err, "Appsec server failed")
return fmt.Errorf("Appsec server failed: %w", err)
}
}
return nil
@ -288,7 +287,7 @@ func (w *AppsecSource) StreamingAcquisition(out chan types.Event, t *tomb.Tomb)
}
if err != nil && err != http.ErrServerClosed {
return errors.Wrap(err, "Appsec server failed")
return fmt.Errorf("Appsec server failed: %w", err)
}
}
return nil

View file

@ -1,13 +1,13 @@
package exprhelpers
import (
"errors"
"fmt"
"time"
"github.com/bluele/gcache"
"github.com/crowdsecurity/crowdsec/pkg/cticlient"
"github.com/crowdsecurity/crowdsec/pkg/types"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
@ -40,7 +40,7 @@ func InitCrowdsecCTI(Key *string, TTL *time.Duration, Size *int, LogLevel *log.L
}
clog := log.New()
if err := types.ConfigureLogger(clog); err != nil {
return errors.Wrap(err, "while configuring datasource logger")
return fmt.Errorf("while configuring datasource logger: %w", err)
}
if LogLevel != nil {
clog.SetLevel(*LogLevel)

View file

@ -2,12 +2,12 @@ package exprhelpers
import (
"context"
"errors"
"os"
"testing"
"time"
"github.com/antonmedv/expr"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -936,7 +936,7 @@ func TestGetDecisionsCount(t *testing.T) {
SaveX(context.Background())
if decision == nil {
require.Error(t, errors.Errorf("Failed to create sample decision"))
require.Error(t, errors.New("Failed to create sample decision"))
}
err = Init(dbClient)
@ -1022,7 +1022,7 @@ func TestGetDecisionsSinceCount(t *testing.T) {
SetOrigin("CAPI").
SaveX(context.Background())
if decision == nil {
require.Error(t, errors.Errorf("Failed to create sample decision"))
require.Error(t, errors.New("Failed to create sample decision"))
}
decision2 := dbClient.Ent.Decision.Create().
@ -1041,7 +1041,7 @@ func TestGetDecisionsSinceCount(t *testing.T) {
SaveX(context.Background())
if decision2 == nil {
require.Error(t, errors.Errorf("Failed to create sample decision"))
require.Error(t, errors.New("Failed to create sample decision"))
}
err = Init(dbClient)
@ -1147,7 +1147,7 @@ func TestGetActiveDecisionsCount(t *testing.T) {
SaveX(context.Background())
if decision == nil {
require.Error(t, errors.Errorf("Failed to create sample decision"))
require.Error(t, errors.New("Failed to create sample decision"))
}
expiredDecision := dbClient.Ent.Decision.Create().
@ -1165,7 +1165,7 @@ func TestGetActiveDecisionsCount(t *testing.T) {
SaveX(context.Background())
if expiredDecision == nil {
require.Error(t, errors.Errorf("Failed to create sample decision"))
require.Error(t, errors.New("Failed to create sample decision"))
}
err = Init(dbClient)
@ -1253,7 +1253,7 @@ func TestGetActiveDecisionsTimeLeft(t *testing.T) {
SaveX(context.Background())
if decision == nil {
require.Error(t, errors.Errorf("Failed to create sample decision"))
require.Error(t, errors.New("Failed to create sample decision"))
}
longerDecision := dbClient.Ent.Decision.Create().
@ -1271,7 +1271,7 @@ func TestGetActiveDecisionsTimeLeft(t *testing.T) {
SaveX(context.Background())
if longerDecision == nil {
require.Error(t, errors.Errorf("Failed to create sample decision"))
require.Error(t, errors.New("Failed to create sample decision"))
}
err = Init(dbClient)