Avoid emitting error on transaction rollback that's complete

It's on purpose
This commit is contained in:
Eli Ribble 2026-05-04 19:53:36 +00:00
parent 347f62bd6d
commit 60bf09e813
No known key found for this signature in database
2 changed files with 11 additions and 1 deletions

View file

@ -23,3 +23,13 @@ func LogOnErrCtx(f ErrorableCtx, ctx context.Context, msg string) {
log.Error().Err(e).Msg(msg) log.Error().Err(e).Msg(msg)
} }
} }
func LogOnErrRollback(f ErrorableCtx, ctx context.Context, msg string) {
e := f(ctx)
if e != nil {
// We're fine with rollbacks that are already properly closed
if e.Error() == "sql: transaction has already been committed or rolled back" {
return
}
log.Error().Err(e).Msg(msg)
}
}

View file

@ -68,7 +68,7 @@ func LoadTemplates() error {
if err != nil { if err != nil {
return fmt.Errorf("Failed to start transaction: %w", err) return fmt.Errorf("Failed to start transaction: %w", err)
} }
defer lint.LogOnErrCtx(tx.Rollback, ctx, "rollback") defer lint.LogOnErrRollback(tx.Rollback, ctx, "rollback")
templateByID = make(map[int32]*builtTemplate, 0) templateByID = make(map[int32]*builtTemplate, 0)
for name, p := range all_templates { for name, p := range all_templates {
template_id, err := templateDBID(tx, name, p) template_id, err := templateDBID(tx, name, p)