Skip to content

Commit

Permalink
fix panic (#39)
Browse files Browse the repository at this point in the history
* fix panic
---------

Co-authored-by: roseduan <[email protected]>
  • Loading branch information
ghosx and roseduan authored Jun 18, 2024
1 parent cce2a07 commit af7806b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func openSegmentFile(dirPath, extName string, id uint32) (*segment, error) {
// set the current block number and block size.
offset, err := fd.Seek(0, io.SeekEnd)
if err != nil {
panic(fmt.Errorf("seek to the end of segment file %d%s failed: %v", id, extName, err))
return nil, fmt.Errorf("seek to the end of segment file %d%s failed: %v", id, extName, err)
}

// init cached block
Expand Down Expand Up @@ -247,8 +247,8 @@ func (seg *segment) writeToBuffer(data []byte, chunkBuffer *bytebufferpool.ByteB
// the buffer length must be equal to chunkSize+padding length
endBufferLen := chunkBuffer.Len()
if position.ChunkSize+padding != uint32(endBufferLen-startBufferLen) {
panic(fmt.Sprintf("wrong!!! the chunk size %d is not equal to the buffer len %d",
position.ChunkSize+padding, endBufferLen-startBufferLen))
return nil, fmt.Errorf("wrong!!! the chunk size %d is not equal to the buffer len %d",
position.ChunkSize+padding, endBufferLen-startBufferLen)
}

// update segment status
Expand Down Expand Up @@ -350,7 +350,7 @@ func (seg *segment) appendChunkBuffer(buf *bytebufferpool.ByteBuffer, data []byt
// write the pending chunk buffer to the segment file
func (seg *segment) writeChunkBuffer(buf *bytebufferpool.ByteBuffer) error {
if seg.currentBlockSize > blockSize {
panic("wrong! can not exceed the block size")
return errors.New("the current block size exceeds the maximum block size")
}

// write the data into underlying file
Expand Down

0 comments on commit af7806b

Please sign in to comment.