Skip to content

[mobile] Fix data readiness JSON response errors - #1460

Merged
Asherlc merged 2 commits into
mainfrom
Asherlc/ios-data-readiness-json
Jul 3, 2026
Merged

Asherlc merged 2 commits into
mainfrom
Asherlc/ios-data-readiness-json

Conversation

@Asherlc

@Asherlc Asherlc commented Jul 3, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Adds mobile tRPC transport diagnostics for empty JSON responses and JSON parser failures.
  • Prevents raw Unexpected end of JSON input from surfacing in data readiness errors by including the tRPC path, status, and content type.
  • Adds regression coverage for empty sync.dataHealth responses and invalid JSON response bodies.

Validation

  • pnpm lint
  • pnpm tsc --noEmit
  • cd packages/server && pnpm tsc --noEmit
  • cd packages/web && pnpm tsc --noEmit
  • pnpm vitest run --project mobile packages/mobile/lib/trpc-fetch.test.ts
  • pnpm test:mobile
  • pnpm vitest run --project integration packages/server/src/routers/router-data.integration.test.ts

Note: full pnpm test reached 705 passing files and then hit the local ClickHouse 3 GiB memory cap in router-data.integration.test.ts; that suite passed when rerun in isolation with .env.local exported.


Summary by cubic

Improves mobile tRPC fetch diagnostics by replacing JSON parsing with clearer errors for empty or invalid bodies, including the tRPC path, HTTP status, and content type. Also reports JSON parse failures to telemetry.

  • Bug Fixes

    • Wraps response.json() to detect empty bodies (including whitespace-only) and throw an actionable error.
    • Converts JSON parse failures into a diagnostic Error with the original SyntaxError as cause, and reports it via telemetry.
    • Handles 204/205/304 or zero-length bodies consistently; valid JSON responses remain unchanged.
  • Tests

    • Adds tests for 204 empty responses, whitespace-only bodies, and invalid JSON (verifies cause and telemetry capture).

Written for commit c0df2f0. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of JSON API responses with no body, now returning a clearer error instead of failing unexpectedly.
    • Enhanced error messages for invalid JSON responses so they better identify the affected request and response status.
  • Tests
    • Added coverage for empty JSON responses and JSON parsing failures.

Copilot AI review requested due to automatic review settings July 3, 2026 00:51
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @Asherlc, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

createTrpcFetch in trpc-fetch.ts now validates JSON responses for empty bodies and wraps response.json() with parse-error diagnostics that include the tRPC procedure path and HTTP status/content-type. Two corresponding test cases were added.

Changes

trpcFetch JSON diagnostics

Layer / File(s) Summary
Empty-body detection and JSON parse diagnostics
packages/mobile/lib/trpc-fetch.ts
Adds responseHasEmptyBody (checks status 204/205/304 or content-length: "0") and withJsonParseDiagnostics (monkey-patches response.json() to rethrow parse errors with path/status/content-type). createTrpcFetch now throws on empty JSON responses instead of returning the raw response, and wraps non-empty JSON responses with the diagnostics helper.
Empty-body and parse-error tests
packages/mobile/lib/trpc-fetch.test.ts
New tests assert rejection with an "empty response" message for a 204 JSON response, and assert JSON parse errors are rewritten to include the tRPC path and status/content-type.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • Asherlc/dofek#1252: Both PRs modify createTrpcFetch in the same file to enrich thrown errors with tRPC path/status diagnostics, one for non-JSON responses and this one for empty/malformed JSON bodies.

Suggested labels: area/mobile, type/bug

Suggested reviewers: cubic-dev-ai

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is imperative, correctly prefixed with [mobile], under 70 characters, and accurately reflects the JSON response error fix.

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.

@github-actions

github-actions Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Storybook previews for 0334f1db are ready:

This comment updates automatically on each PR push.

@github-actions

github-actions Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Mobile Preview

Scan to open on device:

QR code for dofek://preview/pr-1460

Channel pr-1460
Deep Link dofek://preview/pr-1460
Commit 0334f1d

To test on device:

  1. Build and install the preview client: PREVIEW_CHANNEL=pr-1460 pnpm expo prebuild --clean -p ios
  2. Or tap deep link on an existing preview build: dofek://preview/pr-1460

Each PR gets its own channel. Build a preview client with PREVIEW_CHANNEL=pr-{N} to test.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 `@packages/mobile/lib/trpc-fetch.ts`:
- Around line 12-15: The empty-body detection in responseHasEmptyBody is too
heuristic and misses responses that are truly empty but lack a 204/205/304
status or content-length header. Update parseJsonBody to read response.text()
once and check for an empty/whitespace-only body before JSON.parse, then use
that same single read path for both the empty and invalid response error cases.
Keep the existing helpers like getTrpcPath, buildStatusLabel, and
buildContentTypeLabel for the error messages, but remove the separate
body-heuristic branch in responseHasEmptyBody.
- Around line 50-65: The catch in withJsonParseDiagnostics currently drops the
original JSON parse error and does not report it to Sentry. Update the json
override in withJsonParseDiagnostics to catch the thrown error, call
captureException from ./telemetry with that original exception, and then rethrow
a new error that preserves the original as the cause if possible. Keep the
existing getTrpcPath, buildStatusLabel, and buildContentTypeLabel context in the
final message.
🪄 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a980c333-51e9-4d2f-bd71-9f3ffdafa010

📥 Commits

Reviewing files that changed from the base of the PR and between 34ba9af and 16c5556.

📒 Files selected for processing (2)
  • packages/mobile/lib/trpc-fetch.test.ts
  • packages/mobile/lib/trpc-fetch.ts

Comment thread packages/mobile/lib/trpc-fetch.ts Outdated
Comment thread packages/mobile/lib/trpc-fetch.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Adds diagnostic error messages for empty or invalid JSON responses in mobile tRPC fetch, with test coverage.

Re-trigger cubic

@Asherlc Asherlc changed the title Fix mobile data readiness JSON response errors [mobile] Fix data readiness JSON response errors Jul 3, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 2 files (changes from recent commits).

Auto-approved: Improves error handling for empty/invalid JSON responses in mobile tRPC fetch with diagnostics and telemetry.

Re-trigger cubic

@Asherlc

Asherlc commented Jul 3, 2026

Copy link
Copy Markdown
Owner Author

Addressed CodeRabbit title warning.

  • Updated the PR title to [mobile] Fix data readiness JSON response errors.
  • Commit with code review fixes: c0df2f0

@Asherlc
Asherlc merged commit def1484 into main Jul 3, 2026
93 checks passed
@Asherlc
Asherlc deleted the Asherlc/ios-data-readiness-json branch July 3, 2026 01:51
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.

2 participants