Enable catching panics in database calls
This commit is contained in:
parent
8a0849d6da
commit
d16d9cab48
1 changed files with 16 additions and 4 deletions
20
db/db.go
20
db/db.go
|
@ -82,8 +82,13 @@ func Execute(ctx *fibre.Context, txt interface{}) (out []interface{}, err error)
|
|||
|
||||
go execute(ctx, ast, chn)
|
||||
|
||||
for res := range chn {
|
||||
out = append(out, res)
|
||||
for msg := range chn {
|
||||
switch res := msg.(type) {
|
||||
case error:
|
||||
return nil, res
|
||||
default:
|
||||
out = append(out, res)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -145,9 +150,16 @@ func detail(e error) interface{} {
|
|||
}
|
||||
}
|
||||
|
||||
func execute(ctx *fibre.Context, ast *sql.Query, chn chan interface{}) {
|
||||
func execute(ctx *fibre.Context, ast *sql.Query, chn chan<- interface{}) {
|
||||
|
||||
defer close(chn)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if err, ok := r.(error); ok {
|
||||
chn <- err
|
||||
}
|
||||
}
|
||||
close(chn)
|
||||
}()
|
||||
|
||||
for _, s := range ast.Statements {
|
||||
|
||||
|
|
Loading…
Reference in a new issue