Skip to content

Commit cbbcfdd

Browse files
committed
[FEAT] Don't log context cancelled SQL errors
- I found this while doing some unrelated testing in Forgejo. It wasn't my intention to log failed SQL queries if they were cancelled (which can happen quite frequently for larger instances) as in those cases it's not interesting to know which SQL query was run. My intentation was only to log an SQL query if there was an error reported by the database. - Ref go-gitea#2140
1 parent c6a89b4 commit cbbcfdd

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

models/db/engine.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package db
77
import (
88
"context"
99
"database/sql"
10+
"errors"
1011
"fmt"
1112
"io"
1213
"reflect"
@@ -342,7 +343,7 @@ func (ErrorQueryHook) BeforeProcess(c *contexts.ContextHook) (context.Context, e
342343
}
343344

344345
func (h *ErrorQueryHook) AfterProcess(c *contexts.ContextHook) error {
345-
if c.Err != nil {
346+
if c.Err != nil && !errors.Is(c.Err, context.Canceled) {
346347
h.Logger.Log(8, log.ERROR, "[Error SQL Query] %s %v - %v", c.SQL, c.Args, c.Err)
347348
}
348349
return nil

0 commit comments

Comments
 (0)