From 7e831741f9507e11a2272c982c9ea1d791d459ae Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 14 May 2020 15:32:07 +0300 Subject: [PATCH] lib/{storage,mergeset}: return dst on error from unmarshalBlockHeaders, so it could be reused --- lib/mergeset/block_header.go | 6 +++--- lib/storage/block_header.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/mergeset/block_header.go b/lib/mergeset/block_header.go index 6067a9e0e0..67007796b2 100644 --- a/lib/mergeset/block_header.go +++ b/lib/mergeset/block_header.go @@ -148,18 +148,18 @@ func unmarshalBlockHeaders(dst []blockHeader, src []byte, blockHeadersCount int) for i := 0; i < blockHeadersCount; i++ { tail, err := dst[dstLen+i].Unmarshal(src) if err != nil { - return nil, fmt.Errorf("cannot unmarshal block header: %s", err) + return dst, fmt.Errorf("cannot unmarshal block header: %s", err) } src = tail } if len(src) > 0 { - return nil, fmt.Errorf("unexpected non-zero tail left after unmarshaling %d block headers; len(tail)=%d", blockHeadersCount, len(src)) + return dst, fmt.Errorf("unexpected non-zero tail left after unmarshaling %d block headers; len(tail)=%d", blockHeadersCount, len(src)) } newBHS := dst[dstLen:] // Verify that block headers are sorted by firstItem. if !sort.SliceIsSorted(newBHS, func(i, j int) bool { return string(newBHS[i].firstItem) < string(newBHS[j].firstItem) }) { - return nil, fmt.Errorf("block headers must be sorted by firstItem; unmarshaled unsorted block headers: %#v", newBHS) + return dst, fmt.Errorf("block headers must be sorted by firstItem; unmarshaled unsorted block headers: %#v", newBHS) } return dst, nil diff --git a/lib/storage/block_header.go b/lib/storage/block_header.go index 304eb54a37..d41c41167d 100644 --- a/lib/storage/block_header.go +++ b/lib/storage/block_header.go @@ -189,7 +189,7 @@ func unmarshalBlockHeaders(dst []blockHeader, src []byte, blockHeadersCount int) for len(src) > 0 { tmp, err := bh.Unmarshal(src) if err != nil { - return nil, fmt.Errorf("cannot unmarshal block header: %s", err) + return dst, fmt.Errorf("cannot unmarshal block header: %s", err) } src = tmp dst = append(dst, bh) @@ -199,12 +199,12 @@ func unmarshalBlockHeaders(dst []blockHeader, src []byte, blockHeadersCount int) // Verify the number of read block headers. if len(newBHS) != blockHeadersCount { - return nil, fmt.Errorf("invalid number of block headers found: %d; want %d block headers", len(newBHS), blockHeadersCount) + return dst, fmt.Errorf("invalid number of block headers found: %d; want %d block headers", len(newBHS), blockHeadersCount) } // Verify that block headers are sorted by tsid. if !sort.SliceIsSorted(newBHS, func(i, j int) bool { return newBHS[i].TSID.Less(&newBHS[j].TSID) }) { - return nil, fmt.Errorf("block headers must be sorted by tsid; unmarshaled unsorted block headers: %+v", newBHS) + return dst, fmt.Errorf("block headers must be sorted by tsid; unmarshaled unsorted block headers: %+v", newBHS) } return dst, nil