allegro / allegro/bigcache

Improve error handling in BytesQueue.Push function in queue.go

オープン
#400 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る
enhancement good-first-issue
主要言語
Go
スター
8.2k
フォーク
614
平均マージ
5日 12時間
マージ済み PR(30日)
1

説明

The Push function in BytesQueue currently uses a generic error message when the queue is full. It is suggested to use errFullQueue for a more descriptive error message.

Current Code:
```go
var (
errEmptyQueue = &queueError{"Empty queue"}
errInvalidIndex = &queueError{"Index must be greater than zero. Invalid index."}
errIndexOutOfBounds = &queueError{"Index out of range"}
)
```

Push function
```go
if !q.canInsertAfterTail(neededSize) {
if q.canInsertBeforeHead(neededSize) {
q.tail = leftMarginIndex
} else if q.capacity+neededSize >= q.maxCapacity && q.maxCapacity > 0 {
return -1, &queueError{"Full queue. Maximum size limit reached."}
} else {
q.allocateAdditionalMemory(neededSize)
}
}
```

Updated code
```go
var (
errEmptyQueue = &queueError{"Queue is empty."}
errInvalidIndex = &queueError{"Index must be greater than zero. Invalid index."}
errIndexOutOfBounds = &queueError{"Index out of range."}
errFullQueue = &queueError{"Queue is full. Maximum size limit reached."}
)
```
```go
if !q.canInsertAfterTail(neededSize) {
if q.canInsertBeforeHead(neededSize)) {
q.tail = leftMarginIndex
} else if q.capacity+neededSize >= q.maxCapacity && q.maxCapacity > 0 {
return -1, errFullQueue
} else {
q.allocateAdditionalMemory(neededSize)
}
}
```

This will improve the code quality

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。