all: fix Error.New formatting (#2840)

This commit is contained in:
Egon Elbre 2019-08-21 19:30:29 +03:00 committed by GitHub
parent 243cedb628
commit 2d69d47655
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 37 additions and 37 deletions

View File

@ -44,7 +44,7 @@ func TestContainIncrementAndGet(t *testing.T) {
nodeID1 := planet.StorageNodes[1].ID()
_, err = containment.Get(ctx, nodeID1)
require.Error(t, err, audit.ErrContainedNotFound.New(nodeID1.String()))
require.Error(t, err, audit.ErrContainedNotFound.New("%v", nodeID1))
assert.True(t, audit.ErrContainedNotFound.Has(err))
})
}
@ -115,7 +115,7 @@ func TestContainDelete(t *testing.T) {
// get pending audit that doesn't exist
_, err = containment.Get(ctx, info1.NodeID)
assert.Error(t, err, audit.ErrContainedNotFound.New(info1.NodeID.String()))
assert.Error(t, err, audit.ErrContainedNotFound.New("%v", info1.NodeID))
assert.True(t, audit.ErrContainedNotFound.Has(err))
// delete pending audit that doesn't exist
@ -151,7 +151,7 @@ func TestContainUpdateStats(t *testing.T) {
// get pending audit that doesn't exist
_, err = containment.Get(ctx, info1.NodeID)
assert.Error(t, err, audit.ErrContainedNotFound.New(info1.NodeID.String()))
assert.Error(t, err, audit.ErrContainedNotFound.New("%v", info1.NodeID))
assert.True(t, audit.ErrContainedNotFound.Has(err))
})
}

View File

@ -542,13 +542,13 @@ func (verifier *Verifier) checkIfSegmentDeleted(ctx context.Context, segmentPath
newPointer, err = verifier.metainfo.Get(ctx, segmentPath)
if err != nil {
if storage.ErrKeyNotFound.Has(err) {
return nil, ErrSegmentDeleted.New(segmentPath)
return nil, ErrSegmentDeleted.New("%q", segmentPath)
}
return nil, err
}
if oldPointer != nil && oldPointer.CreationDate != newPointer.CreationDate {
return nil, ErrSegmentDeleted.New(segmentPath)
return nil, ErrSegmentDeleted.New("%q", segmentPath)
}
return newPointer, nil
}

View File

@ -155,13 +155,13 @@ func (service *Service) CreateGetOrderLimits(ctx context.Context, bucketID []byt
if node.Disqualified != nil {
service.log.Debug("node is disqualified", zap.Stringer("ID", node.Id))
combinedErrs = errs.Combine(combinedErrs, overlay.ErrNodeDisqualified.New(node.Id.String()))
combinedErrs = errs.Combine(combinedErrs, overlay.ErrNodeDisqualified.New("%v", node.Id))
continue
}
if !service.overlay.IsOnline(node) {
service.log.Debug("node is offline", zap.Stringer("ID", node.Id))
combinedErrs = errs.Combine(combinedErrs, overlay.ErrNodeOffline.New(node.Id.String()))
combinedErrs = errs.Combine(combinedErrs, overlay.ErrNodeOffline.New("%v", node.Id))
continue
}
@ -299,13 +299,13 @@ func (service *Service) CreateDeleteOrderLimits(ctx context.Context, bucketID []
if node.Disqualified != nil {
service.log.Debug("node is disqualified", zap.Stringer("ID", node.Id))
combinedErrs = errs.Combine(combinedErrs, overlay.ErrNodeDisqualified.New(node.Id.String()))
combinedErrs = errs.Combine(combinedErrs, overlay.ErrNodeDisqualified.New("%v", node.Id))
continue
}
if !service.overlay.IsOnline(node) {
service.log.Debug("node is offline", zap.Stringer("ID", node.Id))
combinedErrs = errs.Combine(combinedErrs, overlay.ErrNodeOffline.New(node.Id.String()))
combinedErrs = errs.Combine(combinedErrs, overlay.ErrNodeOffline.New("%v", node.Id))
continue
}
@ -383,13 +383,13 @@ func (service *Service) CreateAuditOrderLimits(ctx context.Context, bucketID []b
if node.Disqualified != nil {
service.log.Debug("node is disqualified", zap.Stringer("ID", node.Id))
combinedErrs = errs.Combine(combinedErrs, overlay.ErrNodeDisqualified.New(node.Id.String()))
combinedErrs = errs.Combine(combinedErrs, overlay.ErrNodeDisqualified.New("%v", node.Id))
continue
}
if !service.overlay.IsOnline(node) {
service.log.Debug("node is offline", zap.Stringer("ID", node.Id))
combinedErrs = errs.Combine(combinedErrs, overlay.ErrNodeOffline.New(node.Id.String()))
combinedErrs = errs.Combine(combinedErrs, overlay.ErrNodeOffline.New("%v", node.Id))
continue
}
@ -461,11 +461,11 @@ func (service *Service) CreateAuditOrderLimit(ctx context.Context, bucketID []by
}
if node.Disqualified != nil {
return nil, storj.PiecePrivateKey{}, overlay.ErrNodeDisqualified.New(nodeID.String())
return nil, storj.PiecePrivateKey{}, overlay.ErrNodeDisqualified.New("%v", nodeID)
}
if !service.overlay.IsOnline(node) {
return nil, storj.PiecePrivateKey{}, overlay.ErrNodeOffline.New(nodeID.String())
return nil, storj.PiecePrivateKey{}, overlay.ErrNodeOffline.New("%v", nodeID)
}
orderLimit, err := signing.SignOrderLimit(ctx, service.satellite, &pb.OrderLimit{
@ -548,13 +548,13 @@ func (service *Service) CreateGetRepairOrderLimits(ctx context.Context, bucketID
if node.Disqualified != nil {
service.log.Debug("node is disqualified", zap.Stringer("ID", node.Id))
combinedErrs = errs.Combine(combinedErrs, overlay.ErrNodeDisqualified.New(node.Id.String()))
combinedErrs = errs.Combine(combinedErrs, overlay.ErrNodeDisqualified.New("%v", node.Id))
continue
}
if !service.overlay.IsOnline(node) {
service.log.Debug("node is offline", zap.Stringer("ID", node.Id))
combinedErrs = errs.Combine(combinedErrs, overlay.ErrNodeOffline.New(node.Id.String()))
combinedErrs = errs.Combine(combinedErrs, overlay.ErrNodeOffline.New("%v", node.Id))
continue
}

View File

@ -127,7 +127,7 @@ func (keys *attributionDB) Get(ctx context.Context, projectID uuid.UUID, bucketN
dbx.ValueAttribution_BucketName(bucketName),
)
if err == sql.ErrNoRows {
return nil, attribution.ErrBucketNotAttributed.New(string(bucketName))
return nil, attribution.ErrBucketNotAttributed.New("%q", bucketName)
}
if err != nil {
return nil, Error.Wrap(err)

View File

@ -30,7 +30,7 @@ func (containment *containment) Get(ctx context.Context, id pb.NodeID) (_ *audit
pending, err := containment.db.Get_PendingAudits_By_NodeId(ctx, dbx.PendingAudits_NodeId(id.Bytes()))
if err != nil {
if err == sql.ErrNoRows {
return nil, audit.ErrContainedNotFound.New(id.String())
return nil, audit.ErrContainedNotFound.New("%v", id)
}
return nil, audit.ContainError.Wrap(err)
}
@ -60,7 +60,7 @@ func (containment *containment) IncrementPending(ctx context.Context, pendingAud
}
case nil:
if !bytes.Equal(existingAudit.ExpectedShareHash, pendingAudit.ExpectedShareHash) {
return audit.ContainError.Wrap(errs.Combine(audit.ErrAlreadyExists.New(pendingAudit.NodeID.String()), tx.Rollback()))
return audit.ContainError.Wrap(errs.Combine(audit.ErrAlreadyExists.New("%v", pendingAudit.NodeID), tx.Rollback()))
}
statement := containment.db.Rebind(
`UPDATE pending_audits SET reverify_count = pending_audits.reverify_count + 1

View File

@ -353,7 +353,7 @@ func (cache *overlaycache) Get(ctx context.Context, id storj.NodeID) (_ *overlay
node, err := cache.db.Get_Node_By_Id(ctx, dbx.Node_Id(id.Bytes()))
if err == sql.ErrNoRows {
return nil, overlay.ErrNodeNotFound.New(id.String())
return nil, overlay.ErrNodeNotFound.New("%v", id)
}
if err != nil {
return nil, err

View File

@ -164,7 +164,7 @@ func (client *Client) Get(ctx context.Context, key storage.Key) (_ storage.Value
err = client.view(func(bucket *bolt.Bucket) error {
data := bucket.Get([]byte(key))
if len(data) == 0 {
return storage.ErrKeyNotFound.New(key.String())
return storage.ErrKeyNotFound.New("%q", key)
}
value = storage.CloneValue(storage.Value(data))
return nil
@ -358,7 +358,7 @@ func (client *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVa
data := bucket.Get([]byte(key))
if len(data) == 0 {
if oldValue != nil {
return storage.ErrKeyNotFound.New(key.String())
return storage.ErrKeyNotFound.New("%q", key)
}
if newValue == nil {
@ -369,7 +369,7 @@ func (client *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVa
}
if !bytes.Equal(storage.Value(data), oldValue) {
return storage.ErrValueChanged.New(key.String())
return storage.ErrValueChanged.New("%q", key)
}
if newValue == nil {

View File

@ -91,7 +91,7 @@ func (client *Client) GetPath(ctx context.Context, bucket, key storage.Key) (_ s
var val []byte
err = row.Scan(&val)
if err == sql.ErrNoRows {
return nil, storage.ErrKeyNotFound.New(key.String())
return nil, storage.ErrKeyNotFound.New("%q", key)
}
return val, Error.Wrap(err)
@ -120,7 +120,7 @@ func (client *Client) DeletePath(ctx context.Context, bucket, key storage.Key) (
return err
}
if numRows == 0 {
return storage.ErrKeyNotFound.New(key.String())
return storage.ErrKeyNotFound.New("%q", key)
}
return nil
}
@ -341,7 +341,7 @@ func (client *Client) CompareAndSwapPath(ctx context.Context, bucket, key storag
if err != nil {
return Error.Wrap(err)
}
return storage.ErrValueChanged.New(key.String())
return storage.ErrValueChanged.New("%q", key)
}
if oldValue == nil {
@ -354,7 +354,7 @@ func (client *Client) CompareAndSwapPath(ctx context.Context, bucket, key storag
var val []byte
err = row.Scan(&val)
if err == sql.ErrNoRows {
return storage.ErrValueChanged.New(key.String())
return storage.ErrValueChanged.New("%q", key)
}
return Error.Wrap(err)
}
@ -399,10 +399,10 @@ func (client *Client) CompareAndSwapPath(ctx context.Context, bucket, key storag
return Error.Wrap(err)
}
if !keyPresent {
return storage.ErrKeyNotFound.New(key.String())
return storage.ErrKeyNotFound.New("%q", key)
}
if !valueUpdated {
return storage.ErrValueChanged.New(key.String())
return storage.ErrValueChanged.New("%q", key)
}
return nil
}

View File

@ -224,7 +224,7 @@ func (client *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVa
value, err := get(ctx, tx, key)
if storage.ErrKeyNotFound.Has(err) {
if oldValue != nil {
return storage.ErrKeyNotFound.New(key.String())
return storage.ErrKeyNotFound.New("%q", key)
}
if newValue == nil {
@ -242,7 +242,7 @@ func (client *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVa
}
if !bytes.Equal(value, oldValue) {
return storage.ErrValueChanged.New(key.String())
return storage.ErrValueChanged.New("%q", key)
}
// runs only if the watched keys remain unchanged
@ -258,7 +258,7 @@ func (client *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVa
err = client.db.Watch(txf, key.String())
if err == redis.TxFailedErr {
return storage.ErrValueChanged.New(key.String())
return storage.ErrValueChanged.New("%q", key)
}
return Error.Wrap(err)
}
@ -267,7 +267,7 @@ func get(ctx context.Context, cmdable redis.Cmdable, key storage.Key) (_ storage
defer mon.Task()(&ctx)(&err)
value, err := cmdable.Get(string(key)).Bytes()
if err == redis.Nil {
return nil, storage.ErrKeyNotFound.New(key.String())
return nil, storage.ErrKeyNotFound.New("%q", key)
}
if err != nil && err != redis.TxFailedErr {
return nil, Error.New("get error: %v", err)

View File

@ -111,7 +111,7 @@ func (store *Client) Get(ctx context.Context, key storage.Key) (_ storage.Value,
keyIndex, found := store.indexOf(key)
if !found {
return nil, storage.ErrKeyNotFound.New(key.String())
return nil, storage.ErrKeyNotFound.New("%q", key)
}
return storage.CloneValue(store.Items[keyIndex].Value), nil
@ -161,7 +161,7 @@ func (store *Client) Delete(ctx context.Context, key storage.Key) (err error) {
keyIndex, found := store.indexOf(key)
if !found {
return storage.ErrKeyNotFound.New(key.String())
return storage.ErrKeyNotFound.New("%q", key)
}
store.delete(keyIndex)
@ -443,7 +443,7 @@ func (store *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVal
keyIndex, found := store.indexOf(key)
if !found {
if oldValue != nil {
return storage.ErrKeyNotFound.New(key.String())
return storage.ErrKeyNotFound.New("%q", key)
}
if newValue == nil {
@ -456,7 +456,7 @@ func (store *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVal
kv := &store.Items[keyIndex]
if !bytes.Equal(kv.Value, oldValue) {
return storage.ErrValueChanged.New(key.String())
return storage.ErrValueChanged.New("%q", key)
}
if newValue == nil {

View File

@ -196,7 +196,7 @@ func (db *ordersDB) Archive(ctx context.Context, requests ...orders.ArchiveReque
if err == nil {
if len(notFoundErrs) > 0 {
// Return a class error to allow to the caler to identify this case
err = orders.OrderNotFoundError.New(notFoundErrs.Err().Error())
err = orders.OrderNotFoundError.Wrap(notFoundErrs.Err())
}
}
} else {