Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2022-01-12 15:12:54 +0300
committerJacob Vosmaer <jacob@gitlab.com>2022-01-17 16:12:05 +0300
commit4b4a2e960636d518c5c223f241d5780624740e2c (patch)
tree8f82313a49e41914ddad58210b5977fad73df0d9 /streamio
parentabdd6cffc874e6578072b20fb0c7991b0b725c56 (diff)
streamio.Reader: remember errors
If there has been an error, subsequent calls to Read should keep returning that error. Changelog: fixed
Diffstat (limited to 'streamio')
-rw-r--r--streamio/stream.go2
-rw-r--r--streamio/stream_test.go20
2 files changed, 21 insertions, 1 deletions
diff --git a/streamio/stream.go b/streamio/stream.go
index 0aab25315..68e6bd687 100644
--- a/streamio/stream.go
+++ b/streamio/stream.go
@@ -23,7 +23,7 @@ type receiveReader struct {
}
func (rr *receiveReader) Read(p []byte) (int, error) {
- if len(rr.data) == 0 {
+ if len(rr.data) == 0 && rr.err == nil {
rr.data, rr.err = rr.receiver()
}
diff --git a/streamio/stream_test.go b/streamio/stream_test.go
index c91d5a58f..8f7c841fd 100644
--- a/streamio/stream_test.go
+++ b/streamio/stream_test.go
@@ -2,6 +2,7 @@ package streamio
import (
"bytes"
+ "errors"
"fmt"
"io"
"strings"
@@ -60,6 +61,25 @@ func TestReadSizes(t *testing.T) {
})
}
+func TestRead_rememberError(t *testing.T) {
+ firstRead := true
+ myError := errors.New("hello world")
+ r := NewReader(func() ([]byte, error) {
+ if firstRead {
+ firstRead = false
+ return nil, myError
+ }
+ panic("should never be reached")
+ })
+
+ // Intentionally call Read more than once. We want the error to be
+ // sticky.
+ for i := 0; i < 10; i++ {
+ _, err := r.Read(nil)
+ require.Equal(t, err, myError)
+ }
+}
+
func receiverFromReader(r io.Reader) func() ([]byte, error) {
return func() ([]byte, error) {
data := make([]byte, 10)