Update command.go

This commit is contained in:
hible 2023-05-05 22:33:22 +08:00
parent 2772a6137f
commit 99cfdfbeac
1 changed files with 12 additions and 7 deletions

View File

@ -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
}