[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 #2140
This commit is contained in:
Gusted 2024-02-12 23:11:50 +01:00
parent c6a89b490d
commit cbbcfdd400
No known key found for this signature in database
GPG key ID: FD821B732837125F

View file

@ -7,6 +7,7 @@ package db
import (
"context"
"database/sql"
"errors"
"fmt"
"io"
"reflect"
@ -342,7 +343,7 @@ func (ErrorQueryHook) BeforeProcess(c *contexts.ContextHook) (context.Context, e
}
func (h *ErrorQueryHook) AfterProcess(c *contexts.ContextHook) error {
if c.Err != nil {
if c.Err != nil && !errors.Is(c.Err, context.Canceled) {
h.Logger.Log(8, log.ERROR, "[Error SQL Query] %s %v - %v", c.SQL, c.Args, c.Err)
}
return nil