errors.Wrap -> fmt.Errorf (#2333)

This commit is contained in:
mmetc 2023-07-06 10:14:45 +02:00 committed by GitHub
parent 486b56d1ed
commit 9967d60987
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 110 additions and 113 deletions

View file

@ -8,6 +8,9 @@ import (
"sync"
"time"
log "github.com/sirupsen/logrus"
"gopkg.in/tomb.v2"
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
@ -16,9 +19,6 @@ import (
"github.com/crowdsecurity/crowdsec/pkg/longpollclient"
"github.com/crowdsecurity/crowdsec/pkg/models"
"github.com/crowdsecurity/crowdsec/pkg/types"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"gopkg.in/tomb.v2"
)
var (
@ -103,7 +103,7 @@ func NewPAPI(apic *apic, dbClient *database.Client, consoleConfig *csconfig.Cons
})
if err != nil {
return &Papi{}, errors.Wrap(err, "failed to create PAPI client")
return &Papi{}, fmt.Errorf("failed to create PAPI client: %w", err)
}
channels := &OperationChannels{
@ -231,7 +231,7 @@ func (p *Papi) Pull() error {
if lastTimestampStr == nil {
binTime, err := lastTimestamp.MarshalText()
if err != nil {
return errors.Wrap(err, "failed to marshal last timestamp")
return fmt.Errorf("failed to marshal last timestamp: %w", err)
}
if err := p.DBClient.SetConfigItem(PapiPullKey, string(binTime)); err != nil {
p.Logger.Errorf("error setting papi pull last key: %s", err)
@ -240,7 +240,7 @@ func (p *Papi) Pull() error {
}
} else {
if err := lastTimestamp.UnmarshalText([]byte(*lastTimestampStr)); err != nil {
return errors.Wrap(err, "failed to unmarshal last timestamp")
return fmt.Errorf("failed to unmarshal last timestamp: %w", err)
}
}
@ -251,7 +251,7 @@ func (p *Papi) Pull() error {
newTime := time.Now().UTC()
binTime, err := newTime.MarshalText()
if err != nil {
return errors.Wrap(err, "failed to marshal last timestamp")
return fmt.Errorf("failed to marshal last timestamp: %w", err)
}
err = p.handleEvent(event, false)
@ -261,7 +261,7 @@ func (p *Papi) Pull() error {
}
if err := p.DBClient.SetConfigItem(PapiPullKey, string(binTime)); err != nil {
return errors.Wrap(err, "failed to update last timestamp")
return fmt.Errorf("failed to update last timestamp: %w", err)
} else {
logger.Debugf("set last timestamp to %s", newTime)
}