Skip to content

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

@github-actions

Description

@github-actions

Note

The pull request "chore: Add try? linter for tests and fix current cases" was created by @itaybre but did not reference an issue. Therefore this issue was created for better visibility in external tools like Linear.

📜 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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions