Skip to content

Conversation

@itaybre
Copy link
Contributor

@itaybre itaybre commented Feb 3, 2026

📜 Description

This PR adds a custom SwiftLint rule to prevent the use of try? (optional try) in test files and fixes all existing occurrences in the codebase.

If we need to use try? in some cases, we can use // swiftlint:disable:next no_try_optional_in_tests

💡 Motivation and Context

Using try? in tests is problematic because it silently converts errors into nil, which can:

  • Hide actual failures in test setup or execution
  • Make tests pass when they should fail
  • Make debugging harder when something goes wrong

By enforcing explicit error handling with try, tests will fail immediately and clearly when errors occur, improving test reliability and debuggability.

💚 How did you test it?

📝 Checklist

You have to check all boxes before merging:

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

Closes #7362

@itaybre itaybre added the ready-to-merge Use this label to trigger all PR workflows label Feb 3, 2026
@itaybre itaybre marked this pull request as draft February 3, 2026 16:22
@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes 🐛

  • In_foreground and is_active app context by philipphofmann in #7188

Internal Changes 🔧

Deps

  • Bump getsentry/craft/.github/workflows/changelog-preview.yml from 2.20.0 to 2.20.1 by dependabot in #7344
  • Bump mikepenz/action-junit-report from 6.1.0 to 6.2.0 by dependabot in #7346

Other

  • Add try? linter for tests and fix current cases by itaybre in #7361
  • Update React Native branch to v8 by itaybre in #7356
  • IPhone 16 Pro default in xcodebuild.sh by philipphofmann in #7348
  • Update GA workflow to use reat native branch with v9 by itaybre in #7342
  • ObjC Integration cleanup by itaybre in #7320

Other

  • Fix missing stack traces for NSException objects reported via NSApplication.shared.reportException(_:) on macOS. by denrase in #7284

🤖 This preview updates automatically when you update the PR.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

return actualItem.data == expectedItem.data
}
}
Copy link

Choose a reason for hiding this comment

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

Envelope comparison throws instead of continuing search on parse failure

Medium Severity

The contains closure now uses try JSONSerialization.jsonObject instead of try?. When iterating over actual envelope items to find a match, if any item contains non-JSON data (like binary attachments), the parsing throws and the entire contains call fails. Previously, parse failures would return false and continue checking other items. This breaks the search pattern—even if a matching JSON item exists in the envelope, encountering a non-parseable item first causes the test to fail.

Fix in Cursor Fix in Web

@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.267%. Comparing base (62649f7) to head (dbda1a2).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #7361       +/-   ##
=============================================
+ Coverage   85.243%   85.267%   +0.023%     
=============================================
  Files          477       478        +1     
  Lines        28577     28589       +12     
  Branches     12418     12430       +12     
=============================================
+ Hits         24360     24377       +17     
+ Misses        4173      4168        -5     
  Partials        44        44               

see 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 62649f7...dbda1a2. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Use this label to trigger all PR workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: Add try? linter for tests and fix current cases

2 participants