Skip to content

Commit 5d11ce4

Browse files
committed
fix: avoid duplicate error messages in WebSocket copy handlers
When the copy handler sends a result or error message to the client, don't also return an error which causes the caller to send another error message.
1 parent 525c048 commit 5d11ce4

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

cmd/api/api/cp.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,8 @@ func (s *ApiService) handleCopyTo(ctx context.Context, ws *websocket.Conn, inst
267267
resultJSON, _ := json.Marshal(result)
268268
ws.WriteMessage(websocket.TextMessage, resultJSON)
269269

270-
if !resp.Success {
271-
return fmt.Errorf("guest copy failed: %s", resp.Error)
272-
}
273-
270+
// Don't return an error here - the result message already contains any error info.
271+
// Returning an error would cause the caller to send a duplicate error message.
274272
return nil
275273
}
276274

@@ -348,7 +346,9 @@ func (s *ApiService) handleCopyFrom(ctx context.Context, ws *websocket.Conn, ins
348346
}
349347
errJSON, _ := json.Marshal(cpErr)
350348
ws.WriteMessage(websocket.TextMessage, errJSON)
351-
return fmt.Errorf("guest error at %s: %s", r.Error.Path, r.Error.Message)
349+
// Don't return an error here - the error message was already sent to the client.
350+
// Returning an error would cause the caller to send a duplicate error message.
351+
return nil
352352
}
353353
}
354354

0 commit comments

Comments
 (0)