mirror of
https://github.com/matrix-org/sliding-sync.git
synced 2025-03-10 13:37:11 +00:00
WithTransaction: dump stack if wrapped func panics
This commit is contained in:
parent
5688b0d2f7
commit
f2b4898446
@ -1,11 +1,21 @@
|
|||||||
package sqlutil
|
package sqlutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/matrix-org/sliding-sync/internal"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
"os"
|
||||||
|
"runtime/debug"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var logger = zerolog.New(os.Stdout).With().Timestamp().Logger().Output(zerolog.ConsoleWriter{
|
||||||
|
Out: os.Stderr,
|
||||||
|
TimeFormat: "15:04:05",
|
||||||
|
})
|
||||||
|
|
||||||
// WithTransaction runs a block of code passing in an SQL transaction
|
// WithTransaction runs a block of code passing in an SQL transaction
|
||||||
// If the code returns an error or panics then the transactions is rolled back
|
// If the code returns an error or panics then the transactions is rolled back
|
||||||
// Otherwise the transaction is committed.
|
// Otherwise the transaction is committed.
|
||||||
@ -18,6 +28,10 @@ func WithTransaction(db *sqlx.DB, fn func(txn *sqlx.Tx) error) (err error) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
panicErr := recover()
|
panicErr := recover()
|
||||||
if err == nil && panicErr != nil {
|
if err == nil && panicErr != nil {
|
||||||
|
// TODO: thread a context through to here?
|
||||||
|
ctx := context.Background()
|
||||||
|
logger.Error().Msg(string(debug.Stack()))
|
||||||
|
internal.GetSentryHubFromContextOrDefault(ctx).RecoverWithContext(ctx, panicErr)
|
||||||
err = fmt.Errorf("panic: %v", panicErr)
|
err = fmt.Errorf("panic: %v", panicErr)
|
||||||
}
|
}
|
||||||
var txnErr error
|
var txnErr error
|
||||||
|
Loading…
x
Reference in New Issue
Block a user