-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Catch Objective-C exceptions from Core Data object query #20755
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
Conversation
|
| App Name | Jetpack Alpha |
|
| Configuration | Release-Alpha | |
| Build Number | pr20755-5672b0d | |
| Version | 22.5 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | 5672b0d | |
| App Center Build | jetpack-installable-builds #4842 |
|
| App Name | WordPress Alpha |
|
| Configuration | Release-Alpha | |
| Build Number | pr20755-5672b0d | |
| Version | 22.5 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | 5672b0d | |
| App Center Build | WPiOS - One-Offs #5811 |
|
I'm not sure I agree with the premise of this PR – IMHO it's preferable for the app to crash rather than give the mistaken impression that data was saved. If the app crashes, the user will validate that their data is safe. If it doesn't, they may discover later that it's missing, which is worse. |
|
I had a chat with Jeremy privately. Here is a recap: The crash was introduced in this commit, where we changed accessing a The root cause of the crash is not caused by data not being saved. Because if that's indeed the case, As I mentioned in #20630 (comment), the crash reason "nil is not an object ID" can't be referencing the The very first attempt of fixing this crash is checking if the object id is a temporary object ID in #20633. Unfortunately that didn't work. However, I should add some code to send debugging logs to Sentry, so that we can gather some data around this |
7c29570 to
9ec21e1
Compare
Generated by 🚫 dangerJS |
mokagio
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving to unblock, but I'd like to hear what Jeremy thinks because of the conversations here and offline between the two of you.
|
|
||
| let blog = try context.existingObject(with: self.blogObjectID) as! Blog | ||
| return MediaHost(with: blog) { error in | ||
| var blog: Result<Blog, Error> = .failure(DownloadError.blogNotFound) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this default value necessary? I don't see a code path where it's used, since if a try in the do-catch throws, the method rethrows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's necessary in terms of making the code look nicer, but also kind of not necessary because the default value will never get used.
The alternative is, we don't give it a default value, then the blog variable needs to be defined as Optional. That means at line 49 where blog.get() is called to get the Blog instance, we need to unwrap the optional blog. Now, if the code ever reaches line 49 at runtime, the blog will never be nil, because no Objective-C exception was thrown and the blog must be a Result instance that wraps a blog object or a Swift Error.
Considering the alternative is unnecessarily unwrapping an Optional, I decided to just give it a default value, which is never going to be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
@crazytonyli good point! I cherry picked in what I thought was going to be my fix PR, #20751, but didn't progress on it because Sergiy's work addressed the issue. |



Another attempt in fixing #20630.
I'm still not sure what's the root cause of the
nil is not a valid object IDerror. But catching the Objective-C exception should prevent the app from crashing.Test Instructions
Open a few posts that have images from the post editor. Make sure images can be loaded.
Regression Notes
Potential unintended areas of impact
None. The refactored
loadObjectfunction wasn't used anywhere, except the unit tests.What I did to test those areas of impact (or what existing automated tests I relied on)
What says in the "Test Instructions"
What automated tests I added (or what prevented me from doing so)
The existing ones have been updated.
PR submission checklist:
RELEASE-NOTES.txtif necessary.UI Changes testing checklist: N/A
Portrait and landscape orientations.Light and dark modes.Fonts: Larger, smaller and bold text.High contrast.VoiceOver.Languages with large words or with letters/accents not frequently used in English.Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)iPhone and iPad.Multi-tasking: Split view and Slide over. (iPad)