Skip to content

Commit 49a54e7

Browse files
committed
refactor(client): streamline error handling in peerTaskConductor and pieceManager
- Consolidate error messages for content length mismatches in peerTaskConductor - Simplify error creation in pieceManager for source response validation - Enhance logging consistency and clarity across error handling Signed-off-by: jinronga <1460595002@qq.com>
1 parent 10a4578 commit 49a54e7

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

client/daemon/peer/peertask_conductor.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -990,10 +990,9 @@ func (pt *peerTaskConductor) updateMetadata(piecePacket *commonv1.PiecePacket) {
990990
pt.Debugf("update content length: %d, dst peer %s", piecePacket.ContentLength, piecePacket.DstPid)
991991
} else if piecePacket.ContentLength > -1 && piecePacket.ContentLength != pt.GetContentLength() {
992992
// corrupt data check
993-
reason := fmt.Sprintf("corrupt data - content length did not match, current: %d, from piece packet: %d",
993+
pt.Errorf("corrupt data - content length did not match, current: %d, from piece packet: %d",
994994
pt.GetContentLength(), piecePacket.ContentLength)
995-
pt.Errorf(reason)
996-
pt.cancel(commonv1.Code_ClientError, reason)
995+
pt.cancel(commonv1.Code_ClientError, "corrupt data - content length did not match")
997996
return
998997
}
999998

@@ -1191,10 +1190,9 @@ func (pt *peerTaskConductor) isCompleted() bool {
11911190

11921191
// corrupt data check and avoid hang for mismatch completed length
11931192
if pt.readyPieces.Settled() == pt.totalPiece.Load() {
1194-
msg := fmt.Sprintf("corrupt data - ready piece count %d seems finished, but completed length %d is not match with content length: %d",
1193+
pt.Errorf("corrupt data - ready piece count %d seems finished, but completed length %d is not match with content length: %d",
11951194
pt.totalPiece.Load(), pt.completedLength.Load(), pt.GetContentLength())
1196-
pt.Errorf(msg)
1197-
pt.cancel(commonv1.Code_ClientError, msg)
1195+
pt.cancel(commonv1.Code_ClientError, "corrupt data - ready piece count seems finished but completed length does not match")
11981196
return true
11991197
}
12001198

client/daemon/peer/piece_manager.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,7 @@ singleDownload:
387387
if err != nil {
388388
log.Errorf("back source status code %d/%s", response.StatusCode, response.Status)
389389
// convert error details to status
390-
st := status.Newf(codes.Aborted,
391-
fmt.Sprintf("source response %d/%s is not valid", response.StatusCode, response.Status))
390+
st := status.Newf(codes.Aborted, "source response %d/%s is not valid", response.StatusCode, response.Status)
392391
hdr := map[string]string{}
393392
for k, v := range response.Header {
394393
if len(v) > 0 {

0 commit comments

Comments
 (0)