feat: Errorf usage

Signed-off-by: haoyun <yun.hao@daocloud.io>
This commit is contained in:
haoyun
2021-12-13 14:31:53 +08:00
parent a04656c1dd
commit c0d07094be
30 changed files with 80 additions and 80 deletions

View File

@@ -193,7 +193,7 @@ func getNextDeviceID(tx *bolt.Tx) (uint32, error) {
}
if seq >= maxDeviceID {
return 0, errors.Errorf("dm-meta: couldn't find free device key")
return 0, errors.New("dm-meta: couldn't find free device key")
}
id := uint32(seq)

View File

@@ -48,7 +48,7 @@ func NewPoolDevice(ctx context.Context, config *Config) (*PoolDevice, error) {
version, err := dmsetup.Version()
if err != nil {
log.G(ctx).Errorf("dmsetup not available")
log.G(ctx).Error("dmsetup not available")
return nil, err
}
@@ -491,7 +491,7 @@ func (p *PoolDevice) GetUsage(deviceName string) (int64, error) {
}
if len(status.Params) == 0 {
return 0, errors.Errorf("failed to get the number of used blocks, unexpected output from dmsetup status")
return 0, errors.New("failed to get the number of used blocks, unexpected output from dmsetup status")
}
count, err := strconv.ParseInt(status.Params[0], 10, 64)

View File

@@ -307,7 +307,7 @@ func (s *Snapshotter) removeDevice(ctx context.Context, key string) error {
deviceName := s.getDeviceName(snapID)
if !s.config.AsyncRemove {
if err := s.pool.RemoveDevice(ctx, deviceName); err != nil {
log.G(ctx).WithError(err).Errorf("failed to remove device")
log.G(ctx).WithError(err).Error("failed to remove device")
// Tell snapshot GC continue to collect other snapshots.
// Otherwise, one snapshot collection failure will stop
// the GC, and all snapshots won't be collected even though
@@ -318,7 +318,7 @@ func (s *Snapshotter) removeDevice(ctx context.Context, key string) error {
// The asynchronous cleanup will do the real device remove work.
log.G(ctx).WithField("device", deviceName).Debug("async remove")
if err := s.pool.MarkDeviceState(ctx, deviceName, Removed); err != nil {
log.G(ctx).WithError(err).Errorf("failed to mark device as removed")
log.G(ctx).WithError(err).Error("failed to mark device as removed")
return err
}
}
@@ -571,7 +571,7 @@ func (s *Snapshotter) Cleanup(ctx context.Context) error {
}
return nil
}); err != nil {
log.G(ctx).WithError(err).Errorf("failed to query devices from metastore")
log.G(ctx).WithError(err).Error("failed to query devices from metastore")
return err
}

View File

@@ -239,7 +239,7 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
if err := t.Commit(); err != nil {
if err1 := os.Rename(renamed, path); err1 != nil {
// May cause inconsistent data on disk
log.G(ctx).WithError(err1).WithField("path", renamed).Errorf("Failed to rename after failed commit")
log.G(ctx).WithError(err1).WithField("path", renamed).Error("Failed to rename after failed commit")
}
return errors.Wrap(err, "failed to commit")
}

View File

@@ -202,7 +202,7 @@ func (o *snapshotter) Remove(ctx context.Context, key string) (err error) {
if renamed != "" {
if err1 := os.Rename(renamed, path); err1 != nil {
// May cause inconsistent data on disk
log.G(ctx).WithError(err1).WithField("path", renamed).Errorf("failed to rename after failed commit")
log.G(ctx).WithError(err1).WithField("path", renamed).Error("failed to rename after failed commit")
}
}
return errors.Wrap(err, "failed to commit")

View File

@@ -273,7 +273,7 @@ func testWalk(ctx context.Context, t *testing.T, _ *MetaStore) {
found := map[string]snapshots.Info{}
err := WalkInfo(ctx, func(ctx context.Context, info snapshots.Info) error {
if _, ok := found[info.Name]; ok {
return errors.Errorf("entry already encountered")
return errors.New("entry already encountered")
}
found[info.Name] = info
return nil

View File

@@ -276,7 +276,7 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
if err := t.Commit(); err != nil {
if err1 := os.Rename(renamed, path); err1 != nil {
// May cause inconsistent data on disk
log.G(ctx).WithError(err1).WithField("path", renamed).Errorf("Failed to rename after failed commit")
log.G(ctx).WithError(err1).WithField("path", renamed).Error("Failed to rename after failed commit")
}
return errors.Wrap(err, "failed to commit")
}