*: drop github.com/pkg/errors dependency

Use standard error wrapping/unwrapping instead. The conversion is mostly
straightforward, but see grpc/grpc-go#2934 for GRPC `status.FromError`, it
doesn't currently support unwrapping/errors.As(), so we're unwrapping manually
here.
This commit is contained in:
Roman Khimov 2021-04-29 18:32:01 +03:00 committed by Roman Khimov
parent ba293a3ff9
commit afbb9d51f1
4 changed files with 17 additions and 11 deletions

View file

@ -3,13 +3,14 @@ package connections
import (
"context"
"crypto/ecdsa"
"errors"
"fmt"
"math/rand"
"sync"
"time"
"github.com/nspcc-dev/neofs-api-go/pkg/client"
"github.com/nspcc-dev/neofs-api-go/pkg/token"
"github.com/pkg/errors"
"google.golang.org/grpc"
)
@ -91,7 +92,7 @@ func new(ctx context.Context, options *PoolBuilderOptions) (Pool, error) {
if epi, err := c.EndpointInfo(ctx); err == nil {
address = epi.NodeInfo().Address()
}
return nil, errors.Wrapf(err, "failed to create neofs session token for client %s", address)
return nil, fmt.Errorf("failed to create neofs session token for client %s: %w", address, err)
}
clientPacks[i] = &clientPack{client: c, sessionToken: st, healthy: true}
}

View file

@ -2,6 +2,8 @@ package downloader
import (
"context"
"errors"
"fmt"
"io"
"net/http"
"path"
@ -14,7 +16,6 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-http-gate/neofs"
"github.com/nspcc-dev/neofs-http-gate/tokens"
"github.com/pkg/errors"
"github.com/valyala/fasthttp"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
@ -84,10 +85,14 @@ func (r *request) receiveFile(options *neofs.GetOptions) {
zap.Error(err),
)
var (
msg = errors.Wrap(err, "could not receive object").Error()
msg = fmt.Sprintf("could not receive object: %v", err)
code = fasthttp.StatusBadRequest
cause = err
)
if st, ok := status.FromError(errors.Cause(err)); ok && st != nil {
for unwrap := errors.Unwrap(err); unwrap != nil; unwrap = errors.Unwrap(cause) {
cause = unwrap
}
if st, ok := status.FromError(cause); ok && st != nil {
if st.Code() == codes.NotFound {
code = fasthttp.StatusNotFound
}
@ -144,7 +149,7 @@ func New(ctx context.Context, log *zap.Logger, plant neofs.ClientPlant) (*Downlo
var err error
d := &Downloader{log: log, plant: plant}
if err != nil {
return nil, errors.Wrap(err, "failed to get neofs client's reusable artifacts")
return nil, fmt.Errorf("failed to get neofs client's reusable artifacts: %w", err)
}
return d, nil
}

1
go.mod
View file

@ -8,7 +8,6 @@ require (
github.com/nspcc-dev/neo-go v0.94.0 // indirect
github.com/nspcc-dev/neofs-api-go v1.25.0
github.com/nspcc-dev/neofs-crypto v0.3.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.9.0
github.com/prometheus/common v0.15.0
github.com/spf13/pflag v1.0.5

View file

@ -4,9 +4,10 @@ import (
"bytes"
"context"
"encoding/base64"
"errors"
"fmt"
"github.com/nspcc-dev/neofs-api-go/pkg/token"
"github.com/pkg/errors"
"github.com/valyala/fasthttp"
)
@ -77,10 +78,10 @@ func fetchBearerToken(ctx *fasthttp.RequestCtx) (*token.BearerToken, error) {
if buf = parse(&ctx.Request.Header); buf == nil {
continue
} else if data, err := base64.StdEncoding.DecodeString(string(buf)); err != nil {
lastErr = errors.Wrap(err, "could not fetch marshaled from base64")
lastErr = fmt.Errorf("can't base64-decode bearer token: %w", err)
continue
} else if err = tkn.Unmarshal(data); err != nil {
lastErr = errors.Wrap(err, "could not unmarshal bearer token")
lastErr = fmt.Errorf("can't unmarshal bearer token: %w", err)
continue
} else if tkn == nil {
continue