Skip to content

Commit

Permalink
throw error upload failure (#2768)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeenkaur authored Dec 10, 2024
1 parent 435fd9b commit 90de602
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions internal/bufferedwrites/buffered_write_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type WriteFileInfo struct {
}

var ErrOutOfOrderWrite = errors.New("outOfOrder write detected")
var ErrUploadFailure = errors.New("error while uploading object to GCS")

// NewBWHandler creates the bufferedWriteHandler struct.
func NewBWHandler(objectName string, bucket gcs.Bucket, blockSize int64, maxBlocks int64, globalMaxBlocksSem *semaphore.Weighted) (bwh *BufferedWriteHandler, err error) {
Expand Down Expand Up @@ -79,7 +80,7 @@ func (wh *BufferedWriteHandler) Write(data []byte, offset int64) (err error) {
// Fail early if the uploadHandler has failed.
select {
case <-wh.uploadHandler.SignalUploadFailure():
return fmt.Errorf("BufferedWriteHandler.Write(): error while uploading object to GCS")
return ErrUploadFailure
default:
break
}
Expand Down Expand Up @@ -127,7 +128,7 @@ func (wh *BufferedWriteHandler) Flush() (err error) {
// Fail early if the uploadHandler has failed.
select {
case <-wh.uploadHandler.SignalUploadFailure():
return fmt.Errorf("file cannot be finalized: error while uploading object to GCS")
return ErrUploadFailure
default:
break
}
Expand Down
4 changes: 2 additions & 2 deletions internal/bufferedwrites/buffered_write_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (testSuite *BufferedWriteTest) TestWrite_SignalUploadFailureInBetween() {

err = testSuite.bwh.Write([]byte("hello"), 5)
require.Error(testSuite.T(), err)
assert.ErrorContains(testSuite.T(), err, "BufferedWriteHandler.Write(): error while uploading object to GCS")
assert.Equal(testSuite.T(), err, ErrUploadFailure)
}

func (testSuite *BufferedWriteTest) TestFlushWithNonNilCurrentBlock() {
Expand Down Expand Up @@ -183,5 +183,5 @@ func (testSuite *BufferedWriteTest) TestFlush_SignalUploadFailureDuringWrite() {

err = testSuite.bwh.Flush()
require.Error(testSuite.T(), err)
assert.ErrorContains(testSuite.T(), err, "file cannot be finalized: error while uploading object to GCS")
assert.Equal(testSuite.T(), err, ErrUploadFailure)
}

0 comments on commit 90de602

Please sign in to comment.