From 99cfdfbeacc0863988fe15f4af2bd7af05c172a9 Mon Sep 17 00:00:00 2001 From: hible <514366607@qq.com> Date: Fri, 5 May 2023 22:33:22 +0800 Subject: [PATCH] Update command.go --- command.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/command.go b/command.go index 4445a6a6..5eaf762c 100644 --- a/command.go +++ b/command.go @@ -1453,14 +1453,19 @@ func readXMessageSlice(rd *proto.Reader) ([]XMessage, error) { } msgs := make([]XMessage, 0, n) - for i := 0; i < n; i++ { - if xMessage, err := readXMessage(rd); err == nil { - msgs = append(msgs, xMessage) + if n > 0 { + var firstError error + for i := 0; i < n; i++ { + if xMessage, err := readXMessage(rd); err == nil { + msgs = append(msgs, xMessage) + } else if firstError == nil { + firstError = err + } + } + if len(msgs) < 1 && firstError != nil { + // Compatible with previous returns + return nil, firstError } - } - if len(msgs) < 1 { - // Compatible with previous returns - return nil, Nil } return msgs, nil }