kvdb/postgres: convert all types of panic data to error

Previously the assumption existed that panic data was already an error.
If that wasn't the case for example because panic("string") was used,
the transaction wasn't unlocked.
This commit is contained in:
Joost Jager
2021-09-27 11:57:23 +02:00
parent 66ca2a994b
commit bd291286f7

View File

@ -151,8 +151,15 @@ func (db *db) getPrefixedTableName(table string) string {
func catchPanic(f func() error) (err error) {
defer func() {
if r := recover(); r != nil {
err = r.(error)
log.Criticalf("Caught unhandled error: %v", err)
log.Criticalf("Caught unhandled error: %v", r)
switch data := r.(type) {
case error:
err = data
default:
err = errors.New(fmt.Sprintf("%v", data))
}
}
}()