refactor: 将fmt.Errorf中的%v替换为%w以保留错误链 (#10050)

替换了多个文件中的错误格式化方式,使用%w包裹原始错误,
保留完整的错误调用链以提升调试时的错误追踪能力。

Co-authored-by: guant <guant@chinaunicom.cn>
This commit is contained in:
aCuteBegCinner
2026-06-22 21:31:45 -07:00
committed by GitHub
co-authored by guant
parent 091d953c34
commit 42ccfc0763
5 changed files with 13 additions and 13 deletions
+1 -1
View File
@@ -199,7 +199,7 @@ func (vc *vidMapClient) LookupVolumeIdsWithFallback(ctx context.Context, volumeI
providerResults, err := vc.provider.LookupVolumeIds(ctx, stillNeedLookup)
if err != nil {
return batchResult, fmt.Errorf("provider lookup failed: %v", err)
return batchResult, fmt.Errorf("provider lookup failed: %w", err)
}
// Update cache with results
+4 -4
View File
@@ -83,7 +83,7 @@ func (t *BalanceTask) Execute(ctx context.Context, params *worker_pb.TaskParams)
t.ReportProgress(10.0)
t.GetLogger().Info("Marking volume readonly for move")
if err := t.markVolumeReadonly(ctx, sourceServer, volumeId); err != nil {
return fmt.Errorf("failed to mark volume readonly: %v", err)
return fmt.Errorf("failed to mark volume readonly: %w", err)
}
// Restore source writability if any subsequent step fails, so the
// source volume is not left permanently readonly on abort.
@@ -102,7 +102,7 @@ func (t *BalanceTask) Execute(ctx context.Context, params *worker_pb.TaskParams)
t.ReportProgress(15.0)
sourceStatus, err := t.readVolumeFileStatus(ctx, sourceServer, volumeId)
if err != nil {
return fmt.Errorf("failed to read source volume status: %v", err)
return fmt.Errorf("failed to read source volume status: %w", err)
}
// Step 3: Copy volume to destination (VolumeCopy also mounts the volume)
@@ -110,7 +110,7 @@ func (t *BalanceTask) Execute(ctx context.Context, params *worker_pb.TaskParams)
t.GetLogger().Info("Copying volume to destination")
lastAppendAtNs, err := t.copyVolume(ctx, sourceServer, targetServer, volumeId)
if err != nil {
return fmt.Errorf("failed to copy volume: %v", err)
return fmt.Errorf("failed to copy volume: %w", err)
}
// Step 4: Tail for updates
@@ -147,7 +147,7 @@ func (t *BalanceTask) Execute(ctx context.Context, params *worker_pb.TaskParams)
t.ReportProgress(90.0)
t.GetLogger().Info("Deleting volume from source server")
if err := t.deleteVolume(ctx, sourceServer, volumeId); err != nil {
return fmt.Errorf("failed to delete volume from source: %v", err)
return fmt.Errorf("failed to delete volume from source: %w", err)
}
sourceMarkedReadonly = false
@@ -96,7 +96,7 @@ func (t *ECBalanceTask) Execute(ctx context.Context, params *worker_pb.TaskParam
// Step 1: Copy shard to destination and mount
t.reportProgress(10.0, "Copying EC shard to destination")
if err := t.copyAndMountShard(ctx, params.VolumeId, sourceAddr, targetAddr, source.ShardIds, target.DiskId); err != nil {
return fmt.Errorf("copy and mount shard: %v", err)
return fmt.Errorf("copy and mount shard: %w", err)
}
// Step 1.5: confirm the destination actually registered the shard(s)
@@ -112,13 +112,13 @@ func (t *ECBalanceTask) Execute(ctx context.Context, params *worker_pb.TaskParam
// Step 2: Unmount shard on source
t.reportProgress(50.0, "Unmounting EC shard from source")
if err := t.unmountShard(ctx, params.VolumeId, sourceAddr, source.ShardIds); err != nil {
return fmt.Errorf("unmount shard on source: %v", err)
return fmt.Errorf("unmount shard on source: %w", err)
}
// Step 3: Delete shard from source
t.reportProgress(75.0, "Deleting EC shard from source")
if err := t.deleteShard(ctx, params.VolumeId, params.Collection, sourceAddr, source.ShardIds); err != nil {
return fmt.Errorf("delete shard on source: %v", err)
return fmt.Errorf("delete shard on source: %w", err)
}
t.reportProgress(100.0, "EC shard move complete")
@@ -131,12 +131,12 @@ func (t *ECBalanceTask) Execute(ctx context.Context, params *worker_pb.TaskParam
func (t *ECBalanceTask) executeDedupDelete(ctx context.Context, volumeID uint32, sourceAddr pb.ServerAddress, shardIDs []uint32) error {
t.reportProgress(25.0, "Unmounting duplicate EC shard")
if err := t.unmountShard(ctx, volumeID, sourceAddr, shardIDs); err != nil {
return fmt.Errorf("unmount duplicate shard: %v", err)
return fmt.Errorf("unmount duplicate shard: %w", err)
}
t.reportProgress(75.0, "Deleting duplicate EC shard")
if err := t.deleteShard(ctx, volumeID, t.collection, sourceAddr, shardIDs); err != nil {
return fmt.Errorf("delete duplicate shard: %v", err)
return fmt.Errorf("delete duplicate shard: %w", err)
}
t.reportProgress(100.0, "Duplicate shard removed")
+1 -1
View File
@@ -521,7 +521,7 @@ func (t *ErasureCodingTask) copyFileFromSource(ctx context.Context, ext, localPa
if len(resp.FileContent) > 0 {
written, writeErr := localFile.Write(resp.FileContent)
if writeErr != nil {
return fmt.Errorf("failed to write to local file: %v", writeErr)
return fmt.Errorf("failed to write to local file: %w", writeErr)
}
totalBytes += int64(written)
}
+2 -2
View File
@@ -82,7 +82,7 @@ func (t *VacuumTask) Execute(ctx context.Context, params *worker_pb.TaskParams)
t.GetLogger().Info("Checking volume status")
targets, currentGarbageRatios, err := t.checkVacuumEligibility(ctx)
if err != nil {
return fmt.Errorf("failed to check vacuum eligibility: %v", err)
return fmt.Errorf("failed to check vacuum eligibility: %w", err)
}
if len(targets) == 0 {
@@ -105,7 +105,7 @@ func (t *VacuumTask) Execute(ctx context.Context, params *worker_pb.TaskParams)
}).Info("Performing vacuum operation")
if err := t.performVacuum(ctx); err != nil {
return fmt.Errorf("failed to perform vacuum: %v", err)
return fmt.Errorf("failed to perform vacuum: %w", err)
}
// Step 3: Verify vacuum results on each target replica.