Skip to content

Commit a16554d

Browse files
authored
fix: slog error log serialization (anomalyco#1276)
1 parent 2553137 commit a16554d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/tui/internal/util/apilogger.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,22 @@ func (h *APILogHandler) Handle(ctx context.Context, r slog.Record) error {
6666

6767
h.mu.Lock()
6868
for _, attr := range h.attrs {
69-
extra[attr.Key] = attr.Value.Any()
69+
val := attr.Value.Any()
70+
if err, ok := val.(error); ok {
71+
extra[attr.Key] = err.Error()
72+
} else {
73+
extra[attr.Key] = val
74+
}
7075
}
7176
h.mu.Unlock()
7277

7378
r.Attrs(func(attr slog.Attr) bool {
74-
extra[attr.Key] = attr.Value.Any()
79+
val := attr.Value.Any()
80+
if err, ok := val.(error); ok {
81+
extra[attr.Key] = err.Error()
82+
} else {
83+
extra[attr.Key] = val
84+
}
7585
return true
7686
})
7787

0 commit comments

Comments
 (0)