Skip to content

fix: harden cache JSON parsing and add debug logging to silent catch blocks#908

Draft
cursor[bot] wants to merge 3 commits intomainfrom
cursor/sentry-cli-bug-fixes-a6d4
Draft

fix: harden cache JSON parsing and add debug logging to silent catch blocks#908
cursor[bot] wants to merge 3 commits intomainfrom
cursor/sentry-cli-bug-fixes-a6d4

Conversation

@cursor
Copy link
Copy Markdown
Contributor

@cursor cursor Bot commented May 4, 2026

Summary

Three robustness fixes for error handling in the CLI's caching and HTTP layers.

Fix 1: Wrap JSON.parse in getCachedDetection() (dsn-cache.ts)

Root cause: getCachedDetection() called JSON.parse() on three stored JSON columns (source_mtimes_json, dir_mtimes_json, all_dsns_json) without try/catch. Corrupted data (partial write, manual DB edit, schema mismatch) would throw an unhandled SyntaxError, crashing DSN detection entirely.

Trigger: Any corruption in the dsn_cache table's JSON columns.

Fix: Wrapped all three JSON.parse() calls in a single try/catch. On failure, the entry is treated as a cache miss (returns undefined), matching the existing pattern used for allResolved parsing in the same file (line 121-127) and repo-cache.ts (line 55-67).

Fix 2: Handle corrupted cursor_stack JSON in getPaginationState() (pagination.ts)

Root cause: getPaginationState() called JSON.parse(row.cursor_stack) without error handling. A corrupt value would throw an unhandled SyntaxError, crashing any pagination command (list issues, list traces, etc.).

Trigger: Corrupted cursor_stack JSON in the pagination_cursors table.

Fix: Added try/catch around the parse. Corrupted rows are deleted (same as expired entries) and the function returns undefined, giving the user a clean first-page result.

Fix 3: Add log.debug() to silent catch blocks in sentry-client.ts

Root cause: Three catch blocks silently swallowed errors with empty handlers, violating the project's catch-block logging rule (AGENTS.md). This made debugging impossible for: (1) token refresh failures after 401, (2) response cache write failures, (3) post-mutation cache invalidation failures.

Trigger: Any error in token refresh, cache write, or cache invalidation.

Fix: Added log.debug() calls in all three catch blocks. Errors remain non-fatal but are now visible in debug output.

Testing

  • All DSN cache tests pass (25/25)
  • All pagination tests pass (21/21)
  • All sentry-client tests pass (13/13)
  • Full test suite: 6633 pass, 27 fail (all pre-existing failures unrelated to these changes)
  • Lint and typecheck pass
Open in Web View Automation 

cursoragent and others added 3 commits May 4, 2026 12:09
…catch

getCachedDetection() called JSON.parse() on three stored JSON columns
(source_mtimes_json, dir_mtimes_json, all_dsns_json) without error
handling. If any stored JSON was corrupt (partial write, manual DB edit,
schema mismatch), the unhandled SyntaxError would crash DSN detection
entirely instead of treating it as a cache miss.

The same file already handles this correctly for allResolved parsing
(line 121-127), and repo-cache.ts uses the same pattern (line 55-67).

Root cause: Missing try/catch around JSON.parse of cached data.
Trigger: Any corruption in the dsn_cache table's JSON columns.

Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
getPaginationState() called JSON.parse(row.cursor_stack) without error
handling. A corrupt cursor_stack value would throw an unhandled
SyntaxError, crashing any pagination command (list issues, traces, etc.)
instead of resetting pagination state.

Now corrupted rows are deleted and treated as fresh state (same as
expired entries), so the user gets a clean first-page result.

Root cause: Missing try/catch around JSON.parse of stored pagination data.
Trigger: Corrupted cursor_stack JSON in the pagination_cursors table.

Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
Three catch blocks in sentry-client.ts silently swallowed errors with
empty handlers, violating the project's catch-block logging rule (see
AGENTS.md). This made debugging impossible for:

1. Token refresh failures after 401 responses (handleUnauthorized)
2. Response cache write failures (cacheResponse)
3. Post-mutation cache invalidation failures (invalidateAfterMutation)

Added log.debug() calls in all three catch blocks. The errors remain
non-fatal (not re-thrown) but are now visible in debug output.

Root cause: Empty catch blocks hiding operational failures.
Trigger: Any error in token refresh, cache write, or cache invalidation.

Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-908/

Built to branch gh-pages at 2026-05-04 12:11 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Codecov Results 📊

6660 passed | Total: 6660 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

❌ Patch coverage is 61.54%. Project has 13515 uncovered lines.
❌ Project coverage is 76.62%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
src/lib/db/pagination.ts 44.44% ⚠️ 5 Missing
src/lib/sentry-client.ts 40.00% ⚠️ 3 Missing
src/lib/db/dsn-cache.ts 83.33% ⚠️ 2 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    76.63%    76.62%    -0.01%
==========================================
  Files          303       303         —
  Lines        57782     57800       +18
  Branches         0         0         —
==========================================
+ Hits         44276     44285        +9
- Misses       13506     13515        +9
- Partials         0         0         —

Generated by Codecov Action

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