Skip to content

Commit 803a366

Browse files
authored
[-] fix serialization of errors in db logger (#744)
1 parent ea681bc commit 803a366

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

internal/pgengine/log_hook.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ func (hook *LogHook) send(cache []logrus.Entry) {
141141
[]string{"ts", "client_name", "pid", "log_level", "message", "message_data"},
142142
pgx.CopyFromSlice(len(cache),
143143
func(i int) ([]any, error) {
144+
if errVal, ok := cache[i].Data[logrus.ErrorKey]; ok {
145+
if e, isErr := errVal.(error); isErr && e != nil {
146+
cache[i].Data[logrus.ErrorKey] = e.Error()
147+
}
148+
}
149+
144150
jsonData, err := json.Marshal(cache[i].Data)
145151
if err != nil {
146152
return nil, err

internal/pgengine/transaction.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,15 @@ func (pge *PgEngine) ExecuteSQLCommand(ctx context.Context, executor executor, t
124124
}
125125
if len(paramValues) == 0 { //mimic empty param
126126
ct, e := executor.Exec(ctx, task.Command)
127-
pge.LogTaskExecution(context.Background(), task, errCodes[err != nil], ct.String(), "")
127+
pge.LogTaskExecution(context.Background(), task, errCodes[e != nil], ct.String(), "")
128128
return e
129129
}
130130
for _, val := range paramValues {
131131
if val == "" {
132132
continue
133133
}
134-
if err = json.Unmarshal([]byte(val), &params); err != nil {
134+
if parseErr := json.Unmarshal([]byte(val), &params); parseErr != nil {
135+
err = errors.Join(err, fmt.Errorf("failed to parse parameter %s: %w", val, parseErr))
135136
return
136137
}
137138
ct, e := executor.Exec(ctx, task.Command, params...)

0 commit comments

Comments
 (0)