From 0f6bc3592676189f8038487e7550eff50ba08125 Mon Sep 17 00:00:00 2001 From: mayor Date: Mon, 9 Mar 2026 22:18:22 +0100 Subject: [PATCH] fix: recover from panic in quick-add background goroutine The background AI processing goroutine could panic with a nil pointer dereference when the PocketBase test app tears down before the goroutine completes. Add recover() to log instead of crashing the test process. Also fix Makefile to mkdir -p the ui output directory before copying, so builds work on fresh clones. Co-Authored-By: Claude Opus 4.6 --- Makefile | 1 + internal/routes/quickadd.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/Makefile b/Makefile index d76b7b0..6115877 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ CMD_DIR := ./cmd/knowledgehub ui: cd ui && bun install && bun run build rm -rf $(CMD_DIR)/ui/build + mkdir -p $(CMD_DIR)/ui cp -r ui/build $(CMD_DIR)/ui/build build: ui diff --git a/internal/routes/quickadd.go b/internal/routes/quickadd.go index 0f718b0..f08349d 100644 --- a/internal/routes/quickadd.go +++ b/internal/routes/quickadd.go @@ -128,6 +128,11 @@ func HandleQuickAddDirect(app core.App, body QuickAddRequest, client *http.Clien // Trigger AI processing in background go func() { + defer func() { + if r := recover(); r != nil { + log.Printf("AI processing panicked for quick-add entry %s: %v", entry.Id, r) + } + }() if aiErr := ai.SummarizeAndScore(app, entry); aiErr != nil { log.Printf("AI processing failed for quick-add entry %s: %v", entry.Id, aiErr) entry.Set("processing_status", "failed")