Skip to content

Commit

Permalink
Update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Suhaibinator committed Jul 1, 2024
1 parent 16b5efa commit 5ddf123
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions server/database/topic_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,18 @@ func (t *Topic) getLatestOffset() (int64, error) {
}

func (t *Topic) getEarliestOffset() (int64, error) {
var offset int64
var nullableOffset sql.NullInt64 // Use sql.NullInt64 to handle NULL values
t.dbMux.RLock()
defer t.dbMux.RUnlock()
err := t.getEarliestOffsetStmt.QueryRow().Scan(&offset)
err := t.getEarliestOffsetStmt.QueryRow().Scan(&nullableOffset)
if err != nil {
if err == sql.ErrNoRows {
// No rows were returned - this means the topic is empty
return 0, errors.ErrTopicIsEmpty
}
return -1, fmt.Errorf("error retrieving from topic: %v", err)
}
return offset, nil
if !nullableOffset.Valid {
// This means the topic is empty or the offset is NULL
return 0, errors.ErrTopicIsEmpty
}
return nullableOffset.Int64, nil
}

func (t *Topic) getLatestMessage() ([]byte, int64, error) {
Expand Down

0 comments on commit 5ddf123

Please sign in to comment.