fix: handle malformed Core JSON responses#158
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a MalformedCoreResponseError class and helpers; processReceived normalizes raw WebSocket payloads, constructs this error on JSON parse failure, routes it to matching pending response entries when possible, and logs warnings with metadata. Tests and component mocks are extended to assert rejection behavior and UI error handling. ChangesMalformed Core Response Handling
Sequence Diagram(s)sequenceDiagram
participant WebSocket
participant CoreAPI as CoreAPI.processReceived
participant ResponsePool
participant Logger as logger.warn
WebSocket->>CoreAPI: incoming raw message (msg.data)
CoreAPI->>CoreAPI: normalize data, attempt JSON.parse
CoreAPI-->>CoreAPI: on parse error, create MalformedCoreResponseError
CoreAPI->>ResponsePool: lookup extracted requestId
alt matching pending request
ResponsePool->>ResponsePool: clear timeout, remove entry
ResponsePool->>CoreAPI: reject pending promise with MalformedCoreResponseError
else no match
CoreAPI->>CoreAPI: reject with MalformedCoreResponseError
end
CoreAPI->>Logger: warn(..., { requestId, dataLength, dataPreview, action })
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/lib/coreApi.ts`:
- Around line 98-105: createSanitizedDataPreview currently builds a full
sanitized copy of data then slices it, which walks and allocates the entire
string; change it to stream and stop after producing 200 characters: iterate
through the input string using an index, use codePointAt to read each Unicode
code point and advance the index by the code point's UTF-16 length (1 or 2),
append either the original character(s) or a single space when the code point is
<=31 or ===127, and break once the output length reaches 200; update the
function name createSanitizedDataPreview and its implementation to avoid
Array.from/map/join and to return the built preview directly.
- Around line 148-158: The current catch path in the
isMalformedCoreResponseError branch logs a warning here (using logger.warn)
which causes duplicate reporting because processReceived already emits
logger.error and caller code like mediaTags() → logMediaApiFailure() also logs;
remove the logger.warn call in this branch and simply return (or rethrow) so
that the caller-specific catch path (e.g., mediaTags / logMediaApiFailure) is
the single place that logs the malformed-core error; apply the same change to
the other occurrence mentioned (lines 661-668) and ensure you reference
isMalformedCoreResponseError and processReceived to locate both spots.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7f36a49d-1929-4845-aa03-87e8febb8526
📒 Files selected for processing (6)
src/__tests__/unit/components/ConnectionProvider.test.tsxsrc/__tests__/unit/components/TagSelector.test.tsxsrc/__tests__/unit/coreApi.api-contract.test.tssrc/__tests__/unit/coreApi.internals.test.tssrc/__tests__/unit/lib/coreApi.test.tssrc/lib/coreApi.ts
Closes #147
Summary
Validated with focused CoreAPI, TagSelector, and ConnectionProvider tests plus typecheck and lint.
Summary by CodeRabbit
Tests
Bug Fixes