Skip to content

Commit

Permalink
Don't panic in health checks
Browse files Browse the repository at this point in the history
The new version of gorm is a bit more panicky so we need to recover and
return a normal error

Signed-off-by: Jonny Stoten <[email protected]>
  • Loading branch information
jonnystoten committed May 12, 2022
1 parent e9fca75 commit edd4687
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion server/storage/sqldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,13 @@ func (db *SQLStorage) Delete(gun data.GUN) error {
}

// CheckHealth asserts that the tuf_files table is present
func (db *SQLStorage) CheckHealth() error {
func (db *SQLStorage) CheckHealth() (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("Panic checking db health: %v", r)
}
}()

tableOk := db.HasTable(&TUFFile{})
if db.Error != nil {
return db.Error
Expand Down
8 changes: 7 additions & 1 deletion signer/keydbstore/sql_keydbstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,13 @@ func (s *SQLKeyDBStore) GetKey(keyID string) data.PublicKey {
}

// HealthCheck verifies that DB exists and is query-able
func (s *SQLKeyDBStore) HealthCheck() error {
func (s *SQLKeyDBStore) HealthCheck() (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("Panic checking db health: %v", r)
}
}()

dbPrivateKey := GormPrivateKey{}
tableOk := s.db.HasTable(&dbPrivateKey)
switch {
Expand Down

0 comments on commit edd4687

Please sign in to comment.