Skip to content

Commit

Permalink
ref(dbtools): return panic stack trace
Browse files Browse the repository at this point in the history
  • Loading branch information
arsham committed Mar 20, 2022
1 parent eac0566 commit 93f13ca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 26 deletions.
25 changes: 5 additions & 20 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dbtools
import (
"context"
"database/sql"
"runtime/debug"
"time"

"github.com/arsham/retry"
Expand Down Expand Up @@ -95,22 +96,14 @@ func (t *Transaction) PGX(ctx context.Context, transactions ...func(pgx.Tx) erro
func() {
defer func() {
if r := recover(); r != nil {
err = errors.Wrapf(errPanic, "%v", r)
err = errors.Wrapf(errPanic, "%v\n%s", r, debug.Stack())
}
}()
err = fn(tx)
}()
if err != nil {
e := errors.Wrap(tx.Rollback(ctx), "rolling back transaction")
e = multierror.Append(err, e).ErrorOrNil()
var (
v1 retry.StopError
v2 *retry.StopError
)
if errors.As(err, &v1) || errors.As(err, &v2) {
e = &retry.StopError{Err: e}
}
return e
return multierror.Append(err, e)
}
}
return errors.Wrap(tx.Commit(ctx), "committing transaction")
Expand Down Expand Up @@ -140,22 +133,14 @@ func (t *Transaction) DB(ctx context.Context, transactions ...func(Tx) error) er
func() {
defer func() {
if r := recover(); r != nil {
err = errors.Wrapf(errPanic, "%v", r)
err = errors.Wrapf(errPanic, "%v\n%s", r, debug.Stack())
}
}()
err = fn(tx)
}()
if err != nil {
e := errors.Wrap(tx.Rollback(), "rolling back transaction")
e = multierror.Append(err, e).ErrorOrNil()
var (
v1 retry.StopError
v2 *retry.StopError
)
if errors.As(err, &v1) || errors.As(err, &v2) {
e = &retry.StopError{Err: e}
}
return e
return multierror.Append(err, e)
}
}
return errors.Wrap(tx.Commit(), "committing transaction")
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/arsham/retry v0.5.0
github.com/arsham/retry v0.5.1
github.com/hashicorp/go-multierror v1.1.1
github.com/jackc/pgconn v1.11.0
github.com/jackc/pgx/v4 v4.15.0
Expand Down Expand Up @@ -52,7 +52,7 @@ require (
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/sys v0.0.0-20220318055525-2edf467146b5 // indirect
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20220317150908-0efb43f6373e // indirect
google.golang.org/grpc v1.45.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/arsham/retry v0.5.0 h1:u9FyqYTDykxCJv6g05r8yvvBWLsb/zBhQH8ItdZ7oSs=
github.com/arsham/retry v0.5.0/go.mod h1:zl7ydR1abWXWqc9+9vKHvwAXp+clY1Pzc6nJ9CSS7W8=
github.com/arsham/retry v0.5.1 h1:TVfq1hC65+2zJaE+F6IeRKayRoD5I+rFHq+25dKZB8A=
github.com/arsham/retry v0.5.1/go.mod h1:zl7ydR1abWXWqc9+9vKHvwAXp+clY1Pzc6nJ9CSS7W8=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
Expand Down Expand Up @@ -1223,8 +1223,8 @@ golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211109184856-51b60fd695b3/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220318055525-2edf467146b5 h1:saXMvIOKvRFwbOMicHXr0B1uwoxq9dGmLe5ExMES6c4=
golang.org/x/sys v0.0.0-20220318055525-2edf467146b5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down

0 comments on commit 93f13ca

Please sign in to comment.