allegro / allegro/bigcache

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

Ouverte
#400 4 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
enhancement good-first-issue
Langage dominant
Go
Étoiles
8.2k
Forks
614
Merge moyen
5 j 12 h
PR mergées (30 j)
1

Description

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

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.