summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-07-14 20:42:34 +0000
committerPeter Stone <thepeterstone@gmail.com>2026-07-16 02:44:52 +0000
commit879e67a95cf994376cbb7e5724a7599c1711b1ec (patch)
treeade8c4d65674d486914c2865f2af733c499ae163
parent146034b08446c4bf0099bb41ab5e689d418e6dce (diff)
fix(tasks): return ErrNativeTaskNotFound from UpdateNativeTask on stale id
HandleWidgetTaskUpdate now returns 404 instead of silently succeeding when the widget's cached task id no longer exists, matching every other native_tasks mutator's checkRowsAffected pattern. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VTUSAEKfsPc6WGDq45yPHD
-rw-r--r--internal/handlers/widget.go4
-rw-r--r--internal/handlers/widget_test.go15
-rw-r--r--internal/store/native_tasks.go8
3 files changed, 25 insertions, 2 deletions
diff --git a/internal/handlers/widget.go b/internal/handlers/widget.go
index 15ef3b2..b8c3aa9 100644
--- a/internal/handlers/widget.go
+++ b/internal/handlers/widget.go
@@ -473,6 +473,10 @@ func (h *Handler) HandleWidgetTaskUpdate(w http.ResponseWriter, r *http.Request)
return
}
if err := h.store.UpdateNativeTask(req.ID, req.Title, req.Description); err != nil {
+ if errors.Is(err, store.ErrNativeTaskNotFound) {
+ http.Error(w, "task not found", http.StatusNotFound)
+ return
+ }
http.Error(w, "failed to update task", http.StatusInternalServerError)
return
}
diff --git a/internal/handlers/widget_test.go b/internal/handlers/widget_test.go
index 35c21e2..95f5264 100644
--- a/internal/handlers/widget_test.go
+++ b/internal/handlers/widget_test.go
@@ -924,6 +924,21 @@ func TestHandleWidgetTaskUpdate_UpdatesTitleAndDescription(t *testing.T) {
}
}
+func TestHandleWidgetTaskUpdate_UnknownID_Returns404(t *testing.T) {
+ s, cleanup := setupTestDB(t)
+ defer cleanup()
+ h := &Handler{store: s}
+
+ body := `{"id":"does-not-exist","title":"New title","description":""}`
+ req := httptest.NewRequest("POST", "/api/widget/task/update", strings.NewReader(body))
+ w := httptest.NewRecorder()
+ http.HandlerFunc(h.HandleWidgetTaskUpdate).ServeHTTP(w, req)
+
+ if w.Code != http.StatusNotFound {
+ t.Errorf("expected 404 for an unknown task id, got %d", w.Code)
+ }
+}
+
func TestHandleWidgetTaskRecurrence_SetsPattern(t *testing.T) {
s, cleanup := setupTestDB(t)
defer cleanup()
diff --git a/internal/store/native_tasks.go b/internal/store/native_tasks.go
index d4cc896..3bd87cb 100644
--- a/internal/store/native_tasks.go
+++ b/internal/store/native_tasks.go
@@ -125,12 +125,16 @@ func (s *Store) CreateNativeTask(task models.Task) error {
}
// UpdateNativeTask updates a native task's content and description.
+// Returns ErrNativeTaskNotFound if id doesn't match any row.
func (s *Store) UpdateNativeTask(id, content, description string) error {
- _, err := s.db.Exec(`
+ result, err := s.db.Exec(`
UPDATE native_tasks SET content = ?, description = ?, updated_at = CURRENT_TIMESTAMP
WHERE id = ?
`, content, description, id)
- return err
+ if err != nil {
+ return err
+ }
+ return checkRowsAffected(result)
}
// UpdateNativeTaskDescription updates only a native task's description, leaving content untouched.