Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore an Objective-C exception #24250

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,13 @@ class MySitesCoordinator: NSObject {
}

@objc func signinDidFinish() {
mySiteViewController = makeMySiteViewController()
navigationController.viewControllers = [rootContentViewController]
// The code below raises an exception during unit tests. Adding a `try?` to ignore the error.
// The exception is Error Domain=NSRangeException Code=0 "(null)". I'm not exactly sure what code (probably
// deep in UIKit) throws this exception, but I don't see any reason the code below would cause crash in production.
try? WPException.objcTry {
self.mySiteViewController = self.makeMySiteViewController()
self.navigationController.viewControllers = [self.rootContentViewController]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose we consider safe to blanket ignore any exception here because we are confident they would arise only when running unit tests due to the many stateful assumption in the app at the moment.

Is that safe?

How would you feel about running this only if NSClassFromString("XCTestCase") != nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be okay because I don't think there is no exception in this code in the real app.

As I shared on Slack, the actual crash site is at this code, which should never happen in the real app too.

I also can't find any related issue on Sentry.

}

func displayJetpackOverlayForDisabledEntryPoint() {
Expand Down