summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAiden Cline <[email protected]>2025-08-19 14:47:44 -0500
committerGitHub <[email protected]>2025-08-19 14:47:44 -0500
commit40bdbf92a368952812954f512b8ded56fc5cb1dd (patch)
treef79d09f6a21142a07ffad02549b56b4e42cfbea4
parentad76d7e57d5c1f03e7fbbe3f5a9d77e44bd437b3 (diff)
downloadopencode-40bdbf92a368952812954f512b8ded56fc5cb1dd.tar.gz
opencode-40bdbf92a368952812954f512b8ded56fc5cb1dd.zip
fix: tui panic from logger (#2075)
-rw-r--r--packages/tui/internal/util/apilogger.go31
1 files changed, 21 insertions, 10 deletions
diff --git a/packages/tui/internal/util/apilogger.go b/packages/tui/internal/util/apilogger.go
index a58be6357..8e872e63a 100644
--- a/packages/tui/internal/util/apilogger.go
+++ b/packages/tui/internal/util/apilogger.go
@@ -2,12 +2,31 @@ package util
import (
"context"
+ "fmt"
"log/slog"
+ "reflect"
"sync"
opencode "github.com/sst/opencode-sdk-go"
)
+func sanitizeValue(val any) any {
+ if val == nil {
+ return nil
+ }
+
+ if err, ok := val.(error); ok {
+ return err.Error()
+ }
+
+ v := reflect.ValueOf(val)
+ if v.Kind() == reflect.Interface && !v.IsNil() {
+ return fmt.Sprintf("%T", val)
+ }
+
+ return val
+}
+
type APILogHandler struct {
client *opencode.Client
service string
@@ -67,21 +86,13 @@ func (h *APILogHandler) Handle(ctx context.Context, r slog.Record) error {
h.mu.Lock()
for _, attr := range h.attrs {
val := attr.Value.Any()
- if err, ok := val.(error); ok {
- extra[attr.Key] = err.Error()
- } else {
- extra[attr.Key] = val
- }
+ extra[attr.Key] = sanitizeValue(val)
}
h.mu.Unlock()
r.Attrs(func(attr slog.Attr) bool {
val := attr.Value.Any()
- if err, ok := val.(error); ok {
- extra[attr.Key] = err.Error()
- } else {
- extra[attr.Key] = val
- }
+ extra[attr.Key] = sanitizeValue(val)
return true
})