fix: harden cache JSON parsing and add debug logging to silent catch blocks#908
Draft
cursor[bot] wants to merge 3 commits intomainfrom
Draft
fix: harden cache JSON parsing and add debug logging to silent catch blocks#908cursor[bot] wants to merge 3 commits intomainfrom
cursor[bot] wants to merge 3 commits intomainfrom
Conversation
…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>
Contributor
|
Contributor
Codecov Results 📊✅ 6660 passed | Total: 6660 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 61.54%. Project has 13515 uncovered lines. Files with missing lines (3)
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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()calledJSON.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 unhandledSyntaxError, crashing DSN detection entirely.Trigger: Any corruption in the
dsn_cachetable'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 (returnsundefined), matching the existing pattern used forallResolvedparsing in the same file (line 121-127) andrepo-cache.ts(line 55-67).Fix 2: Handle corrupted
cursor_stackJSON ingetPaginationState()(pagination.ts)Root cause:
getPaginationState()calledJSON.parse(row.cursor_stack)without error handling. A corrupt value would throw an unhandledSyntaxError, crashing any pagination command (list issues,list traces, etc.).Trigger: Corrupted
cursor_stackJSON in thepagination_cursorstable.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.tsRoot 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