Skip to content

Commit

Permalink
Fix ReadOnlyDB close error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hifi committed Jan 26, 2024
1 parent 3226416 commit 58d075e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions dbutil/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,12 @@ type Config struct {
func (db *Database) Close() error {
err := db.RawDB.Close()
if db.ReadOnlyDB != nil {
err2 := db.ReadOnlyDB.Close()
if err == nil {
err = fmt.Errorf("closing read-only db failed: %w", err2)
} else {
err = fmt.Errorf("%w (closing read-only db also failed: %v)", err, err2)
if err2 := db.ReadOnlyDB.Close(); err2 != nil {
if err == nil {
err = fmt.Errorf("closing read-only db failed: %w", err2)
} else {
err = fmt.Errorf("%w (closing read-only db also failed: %v)", err, err2)
}
}
}
return err
Expand Down

0 comments on commit 58d075e

Please sign in to comment.