Skip to content

fix(api): surface DB query errors instead of 200 OK zeros - #91

Closed
Fl0p wants to merge 2 commits into
mainfrom
flo-593-handler-query-errors
Closed

fix(api): surface DB query errors instead of 200 OK zeros#91
Fl0p wants to merge 2 commits into
mainfrom
flo-593-handler-query-errors

Conversation

@Fl0p

@Fl0p Fl0p commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Read handlers in internal/api/handler.go no longer discard Query/QueryRow errors; failures return JSON {"error":"..."} with a non-2xx status instead of a confident 200 of zeros.
  • sql.ErrNoRows still yields empty/zero payloads (fresh install safe); every rows.Next() loop checks rows.Err().
  • Table-driven tests cover /overview and /costs for query-failure → non-2xx and empty-DB → 200 with zeros.

Test plan

  • go build ./...
  • go test ./internal/api/...
  • CI green on PR head
  • Spot-check: forced query failure returns ErrorState-compatible JSON, empty DB still shows zeros

Made with Cursor

@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cf11bdb6-c258-42d6-aba6-65da01872f87


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Soren and others added 2 commits August 21, 2026 01:11
Read handlers were discarding Query/QueryRow errors and returning
confident zero payloads. Propagate failures as JSON 5xx, keep ErrNoRows
as empty data, and check rows.Err after every scan loop.

Co-Authored-By: Soren <soren@agents.flopbut.local>
Co-Authored-By: Cursor Composer 2.5 <noreply@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Scan leaves SessionID empty on any failure, so checking the empty value
before the error made every query failure on /sessions/{id} render as
"not found" and left the query-failed branch unreachable. A missing
session still 404s via ErrNoRows.

Covers the single-row handlers with a QueryRow-failing stub, and adds
/models and both /history series paths to the query-failure table.

Co-Authored-By: Daedalus <daedalus@agents.flopbut.local>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Fl0p
Fl0p force-pushed the flo-593-handler-query-errors branch from a76080d to ce10e53 Compare August 20, 2026 23:12
@Fl0p

Fl0p commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Merged to main as d3d51b0 via local squash (agent identity preserved per the merge policy), so GitHub will not auto-close this.

Rebased onto main first: feat(history) had since split handleHistory into historyRawSeries/historyUnionSeries, which have no ResponseWriter in scope — those helpers now return error and handleHistory maps it to queryFailed. That conflict was also why CI stopped scheduling: the PR was CONFLICTING, so GitHub could not build the merge ref.

One review fix on top: /sessions/{id} checked resp.SessionID == "" before err != nil, and Scan leaves the destination untouched on failure — so a broken DB reported 404 not found and the queryFailed branch was unreachable. Ordering fixed, regression test added.

@Fl0p Fl0p closed this Aug 20, 2026
@Fl0p
Fl0p deleted the flo-593-handler-query-errors branch August 20, 2026 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant