Skip to content

Report every handled mobile error to Sentry - #1896

Merged
Asherlc merged 3 commits into
mainfrom
issue-1795
Jul 24, 2026
Merged

Asherlc merged 3 commits into
mainfrom
issue-1795

Conversation

@Asherlc

@Asherlc Asherlc commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • report handled unexpected mobile errors through the canonical telemetry helper with stable source tags
  • model native Apple sign-in cancellation and unavailable optional haptics as expected outcomes
  • enforce the invariant with a TypeScript AST policy wired into canonical lint and representative tests

Validation

  • pnpm lint
  • pnpm tsc --noEmit
  • cd packages/server && pnpm tsc --noEmit
  • cd packages/web && pnpm tsc --noEmit
  • signed Release simulator build and actionable password-auth failure audit
  • pnpm test (765 files, 13,242 tests)

Closes #1795

Copilot AI review requested due to automatic review settings July 24, 2026 15:56
@Asherlc Asherlc linked an issue Jul 24, 2026 that may be closed by this pull request
6 tasks
@cursor

cursor Bot commented Jul 24, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@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 →

@codereviewbot-ai

Copy link
Copy Markdown

🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews.

@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 24, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Asherlc, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 31 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: df963d7d-0505-4ae1-b6c6-f3d28b61134e

📥 Commits

Reviewing files that changed from the base of the PR and between 4859f31 and 0be7fbb.

📒 Files selected for processing (13)
  • package.json
  • packages/mobile/app/imu-visualization.test.tsx
  • packages/mobile/app/providers/auth-modals.test.tsx
  • packages/mobile/app/providers/auth-modals.tsx
  • packages/mobile/lib/inertial-measurement-unit-service.test.ts
  • packages/mobile/lib/inertial-measurement-unit-service.ts
  • packages/mobile/lib/telemetry.test.ts
  • packages/mobile/lib/telemetry.ts
  • packages/mobile/lib/useHaptic.test.ts
  • packages/mobile/lib/useHaptic.ts
  • packages/mobile/package.json
  • scripts/mobile-catch-telemetry-policy.test.ts
  • scripts/mobile-catch-telemetry-policy.ts
📝 Walkthrough

Walkthrough

The mobile package now reports handled unexpected errors through structured telemetry, preserves explicit cancellation and optional-haptic behavior, migrates WHOOP sync paths to the local helper, and adds an AST-based lint policy with tests.

Changes

Mobile telemetry policy

Layer / File(s) Summary
AST policy and lint integration
scripts/mobile-catch-telemetry-policy.ts, scripts/mobile-catch-telemetry-policy.test.ts, package.json, packages/mobile/package.json
Adds syntax-aware detection for consumed errors, approved rethrows/captures, optional haptics, production scanning, and lint command integration.
Application failure telemetry
packages/mobile/app/ble-probe.tsx, packages/mobile/app/heart-rate-visualization.tsx, packages/mobile/app/imu-visualization.tsx, packages/mobile/app/*test.tsx
Adds stable telemetry sources for BLE and visualization failures and tests representative native and connection errors.
Authentication and provider handling
packages/mobile/app/login.tsx, packages/mobile/app/providers/auth-modals.tsx, packages/mobile/lib/auth.ts, packages/mobile/lib/apple-health-provider.ts, packages/mobile/components/DataExportSection.tsx, related tests
Reports provider, auth, modal, and parsing failures while modeling Apple cancellation and authorization fallback behavior.
Background and sensor synchronization
packages/mobile/lib/background-*.ts, packages/mobile/lib/health-kit-sync.ts, packages/mobile/lib/inertial-measurement-unit-service.ts, related tests
Reports non-fatal WHOOP, HealthKit, Watch, and CoreMotion failures with operation-specific metadata.
Utility and optional operations
packages/mobile/lib/open-external-url.ts, packages/mobile/lib/trpc-fetch.ts, packages/mobile/lib/useHaptic.ts, related tests
Reports URL and response-processing failures and represents unavailable haptics with a typed result.

Estimated code review effort: 4 (Complex) | ~45 minutes

Assessment against linked issues

Objective Addressed Explanation
Failing tests cover representative handled errors [#1795]
Unexpected handled errors report the original error with stable sources [#1795]
Existing user-visible and fallback behavior remains preserved [#1795]
Cancellations, optional haptics, and future consumed-error paths are explicitly modeled [#1795]

Possibly related PRs

  • Asherlc/dofek#1252: Both modify packages/mobile/lib/trpc-fetch.ts response and URL error handling.
  • Asherlc/dofek#1394: Both modify authentication response handling in packages/mobile/lib/auth.ts.
  • Asherlc/dofek#1405: Both modify Apple Health provider authorization error handling.

Suggested labels: area/mobile, type/feature

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 1 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title matches the change, but it is missing the required mobile area prefix. Prefix the title with an area tag such as [mobile]: "[mobile] Report every handled mobile error to Sentry".
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

@codereviewbot-ai

codereviewbot-ai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Overall, great PR! Standardizing error handling and routing exceptions through the centralized captureException telemetry helper with explicit source tags across all mobile features significantly improves observability and telemetry consistency.

I've left one small inline suggestion in packages/mobile/lib/auth.ts to support both ERR_REQUEST_CANCELED and ERR_CANCELED error codes for native Apple sign-in cancellations.


🤖 Reviewed by codereviewbot.ai - Catch bugs before your team does.

@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Mobile Preview

Scan to open on device:

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

Channel pr-1896
Deep Link dofek://preview/pr-1896
Commit 050f178

To test on device:

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

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

Comment thread packages/mobile/lib/auth.ts

@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: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/mobile/lib/inertial-measurement-unit-service.ts (1)

117-123: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use a distinct source for WHOOP streaming-start failures.

This catch covers both findAndConnect() and startStreaming(), but every failure is tagged activity-recording-whoop-connect. A successful connection followed by a failed stream start will be misclassified. Split the handlers or use a source describing the complete setup, and add a regression test for startStreaming() rejection.

🤖 Prompt for 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.

In `@packages/mobile/lib/inertial-measurement-unit-service.ts` around lines 117 -
123, Update the WHOOP setup flow around findAndConnect and startStreaming so
startStreaming rejection is captured with a distinct streaming-start source
instead of activity-recording-whoop-connect; split the try/catch handlers while
preserving connection failure classification, and add a regression test covering
startStreaming rejection.
🤖 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/app/imu-visualization.tsx`:
- Around line 84-87: Add representative IMU visualization tests covering both
native streaming/connection error catch paths around the start-streaming and
connection handling logic. Mock the native failures, verify errors are caught
and consumed, and assert captureException is called with the stable sources
"imu-visualization-start-streaming" and the corresponding connection source.

In `@packages/mobile/app/providers/auth-modals.test.tsx`:
- Around line 1-59: Extend the auth-modals test suite beyond CredentialAuthModal
to cover GarminAuthModal sign-in telemetry and WhoopAuthModal sign-in and
verification telemetry. Mock each relevant mutation, trigger the corresponding
UI flows, and assert mockCaptureException receives the original error with the
expected source and providerId metadata while preserving the actionable error
message.

In `@packages/mobile/lib/background-watch-inertial-measurement-unit-sync.ts`:
- Around line 112-113: Update the shared telemetry helper in
packages/mobile/lib/telemetry.ts so the context’s source value is sent to Sentry
as a tag rather than only as extra data; this root-cause fix should cover the
source callers in
packages/mobile/lib/background-watch-inertial-measurement-unit-sync.ts
(112-113), packages/mobile/lib/background-whoop-ble-sync.ts (153-157, 170-174,
210-214, 236-240, 285-291, 308-313, 475-480),
packages/mobile/lib/useWhoopBleSync.ts (30-30), and
packages/mobile/lib/trpc-fetch.ts (28-32, 45-47), which require no direct
changes.

In `@packages/mobile/lib/useHaptic.ts`:
- Around line 14-23: Update performOptionalHaptic in
packages/mobile/lib/useHaptic.ts:14-23 to identify and suppress only the
documented unavailable-haptics error, call captureException() for every
unexpected rejection, and preserve the unavailable result for the documented
case. Update packages/mobile/lib/useHaptic.test.ts:47-57 to retain coverage for
the documented unavailable condition and add coverage asserting unexpected
rejections trigger telemetry.

In `@scripts/mobile-catch-telemetry-policy.ts`:
- Around line 13-37: Update containsCanonicalCaptureOrThrow to evaluate
reachability rather than merely finding any throw or captureException
descendant. Ensure unreachable branches such as if (false) do not satisfy the
policy, while reporting or propagating the actual catch-path error still does;
add a regression test in mobile-catch-telemetry-policy.test.ts covering an
unreachable throw alongside a swallowing path.
- Around line 39-108: Update hasOptionalHapticResultReturnType to resolve and
validate the referenced OptionalHapticResult type in the current source context
instead of matching only its annotation text. Confirm the local alias represents
the expected union from useHaptic.ts: a performed status variant and an
unavailable status variant carrying cause; return false for same-named types
with any other shape, while preserving the existing exemption flow in
isExplicitOptionalHapticUnavailableResult.

---

Outside diff comments:
In `@packages/mobile/lib/inertial-measurement-unit-service.ts`:
- Around line 117-123: Update the WHOOP setup flow around findAndConnect and
startStreaming so startStreaming rejection is captured with a distinct
streaming-start source instead of activity-recording-whoop-connect; split the
try/catch handlers while preserving connection failure classification, and add a
regression test covering startStreaming rejection.
🪄 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: 1fff4b27-63ad-4e1b-9a7d-f38a149366e7

📥 Commits

Reviewing files that changed from the base of the PR and between 011132e and 4859f31.

📒 Files selected for processing (31)
  • package.json
  • packages/mobile/app/ble-probe.test.tsx
  • packages/mobile/app/ble-probe.tsx
  • packages/mobile/app/heart-rate-visualization.test.tsx
  • packages/mobile/app/heart-rate-visualization.tsx
  • packages/mobile/app/imu-visualization.tsx
  • packages/mobile/app/login.test.tsx
  • packages/mobile/app/login.tsx
  • packages/mobile/app/providers/auth-modals.test.tsx
  • packages/mobile/app/providers/auth-modals.tsx
  • packages/mobile/components/DataExportSection.tsx
  • packages/mobile/lib/apple-health-provider.ts
  • packages/mobile/lib/auth.test.ts
  • packages/mobile/lib/auth.ts
  • packages/mobile/lib/background-watch-inertial-measurement-unit-sync.ts
  • packages/mobile/lib/background-whoop-ble-sync.test.ts
  • packages/mobile/lib/background-whoop-ble-sync.ts
  • packages/mobile/lib/health-kit-sync.test.ts
  • packages/mobile/lib/health-kit-sync.ts
  • packages/mobile/lib/inertial-measurement-unit-service.test.ts
  • packages/mobile/lib/inertial-measurement-unit-service.ts
  • packages/mobile/lib/open-external-url.test.ts
  • packages/mobile/lib/open-external-url.ts
  • packages/mobile/lib/trpc-fetch.ts
  • packages/mobile/lib/useHaptic.test.ts
  • packages/mobile/lib/useHaptic.ts
  • packages/mobile/lib/useWhoopBleSync.ts
  • packages/mobile/package.json
  • packages/mobile/test-setup.ts
  • scripts/mobile-catch-telemetry-policy.test.ts
  • scripts/mobile-catch-telemetry-policy.ts

Comment thread packages/mobile/app/imu-visualization.tsx
Comment thread packages/mobile/app/providers/auth-modals.test.tsx
Comment thread packages/mobile/lib/useHaptic.ts
Comment thread scripts/mobile-catch-telemetry-policy.ts Outdated
Comment thread scripts/mobile-catch-telemetry-policy.ts Outdated
@codereviewbot-ai

Copy link
Copy Markdown

🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews.

@Asherlc

Asherlc commented Jul 24, 2026

Copy link
Copy Markdown
Owner Author

Fixed the outside-diff WHOOP streaming finding from #1896 (review).

  • Split WHOOP connection and streaming startup into separate handled operations.
  • Streaming startup failures now use source activity-recording-whoop-start-streaming; connection failures retain activity-recording-whoop-connect.
  • Added regression coverage for both sources.
  • The six inline findings from the same review were answered in their respective threads.
  • Commit: 0be7fbb77

@github-actions

Copy link
Copy Markdown
Contributor

Storybook previews for 050f1789 are ready:

This comment updates automatically on each PR push.

@Asherlc
Asherlc merged commit ebe2c35 into main Jul 24, 2026
113 checks passed
@Asherlc
Asherlc deleted the issue-1795 branch July 24, 2026 16:40
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.

Report every handled unexpected mobile error to Sentry

2 participants