wordpress-mobile / WordPress-iOS

WordPress for iOS - Official repository
http://ios.wordpress.org/
GNU General Public License v2.0
3.7k stars 1.12k forks source link

NSInvalidArgumentException: -[__NSCFType encodeWithCoder:]: unrecognized selector sent to instance 0x1032f2600 #14963

Open jkmassel opened 4 years ago

jkmassel commented 4 years ago

Sentry Url: https://sentry.io/share/issue/e8f83bc0ac2648e696b58ada13f6e31b/ User Count: 93 Count: 149 First Release: 15.3.0.3 First Seen: 2020-08-18T21:08:38Z Last Seen: 2020-09-21T18:02:10Z 24 Hours: 3 30 Days: 148 LogID: BA1FBB6A-00EE-41B8-A189-757FD8A38A22

NSInvalidArgumentException: nil is not a valid object ID
  File "MediaProgressCoordinatorNoticeViewModel.swift", line 169, in MediaProgressCoordinatorNoticeViewModel.blogInContext.getter
  File "<compiler-generated>", line null, in MediaProgressCoordinatorNoticeViewModel.blogInContext.getter
  File "MediaProgressCoordinatorNoticeViewModel.swift", line 78, in MediaProgressCoordinatorNoticeViewModel.notificationInfo.getter
  File "MediaProgressCoordinatorNoticeViewModel.swift", line 65, in MediaProgressCoordinatorNoticeViewModel.failureNotice.getter
  File "MediaProgressCoordinatorNoticeViewModel.swift", line 43, in MediaProgressCoordinatorNoticeViewModel.notice.getter
  File "MediaCoordinator.swift", line 681, in MediaCoordinator.mediaProgressCoordinatorDidFinishUpload
  File "<compiler-generated>", line null, in MediaCoordinator.mediaProgressCoordinatorDidFinishUpload
  File "MediaProgressCoordinator.swift", line 284, in MediaProgressCoordinator.refreshMediaProgress
  File "MediaProgressCoordinator.swift", line 275, in MediaProgressCoordinator.observeValue
  File "<compiler-generated>", line null, in @callee_guaranteed
  File "main.swift", line 7, in main
...
(12 additional frame(s) were not displayed)
bummytime commented 4 years ago

@diegoreymendez @frosty @guarani, another nil is not a valid object ID this time in MediaProgressCoordinator. 😢

designsimply commented 4 years ago

@bummytime would you like to assign this one since you marked it as high priority and it's a new crash? Alternately, you could de-escalate it if you feel the important Media issues already have attention right now.

Events in the last 90d: 202 Users affected in the last 90d: 127 WORDPRESS-IOS-38VR: https://sentry.io/share/issue/e8f83bc0ac2648e696b58ada13f6e31b/

image

guarani commented 4 years ago

FWIW, I had a look at this earlier today and I think it could be related to https://github.com/wordpress-mobile/WordPress-iOS/issues/14960. Both are due to blog.objectID being nil albeit in different areas of media-related code.

diegoreymendez commented 4 years ago

I managed to reproduce the issue.

Prerequisites:

These modifications are used to force the specific situation in which media.blog is NULL, while only affecting the part of the code we want to crash (by instead using daBlog.

Add this to Media.h:

@property (nonatomic, strong, readonly) Blog *daBlog;

Add this to Media.m:

- (Blog *)daBlog
{
    return NULL;
}

Change line 167 of MediaProgressCoordinatorNoticeViewModel.swift to:

var blog = media.daBlog

Steps:

  1. Launch the App
  2. Pick a WP.com site
  3. Go to your Media Library.
  4. Tap + to upload an image from your device.
  5. Upload an image.
  6. When the image finished uploading you should see the crash.

The symbols are a bit off for me (not sure why) but it's crashing in the exact same spot with the exact same message:

2020-10-01 11:11:55.319878-0300 WordPress[71994:812930] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'nil is not a valid object ID'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff2043a126 __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x00007fff20177f78 objc_exception_throw + 48
    2   CoreData                            0x00007fff250f9b08 -[NSFaultHandler fulfillFault:withContext:error:] + 0
    3   WordPress                           0x0000000108aad107 $s9WordPress39MediaProgressCoordinatorNoticeViewModelV13blogInContext33_027770C62B8AC1DD8D3D2271DD2F4928LLSo4BlogCSgvg + 1239
    4   WordPress                           0x0000000108aab627 $s9WordPress39MediaProgressCoordinatorNoticeViewModelV07successF033_027770C62B8AC1DD8D3D2271DD2F4928LLAA0F0Vvg + 199
    5   WordPress                           0x0000000108aab53d $s9WordPress39MediaProgressCoordinatorNoticeViewModelV6noticeAA0F0VSgvg + 141
    6   WordPress                           0x0000000109040f8b $s9WordPress16MediaCoordinatorC013mediaProgressD15DidFinishUploadyyAA0cfD0CF + 1291
    7   WordPress                           0x0000000109041df4 $s9WordPress16MediaCoordinatorC013mediaProgressD15DidFinishUploadyyAA0cfD0CFTo + 68
    8   WordPress                           0x000000010917bf9e $s9WordPress24MediaProgressCoordinatorC07refreshcD033_E4E6231F30812010CC2D864A8028052BLLyyF + 334
    9   WordPress                           0x000000010917bb0b $s9WordPress24MediaProgressCoordinatorC12observeValue10forKeyPath2of6change7contextySSSg_ypSgSDySo05NSKeyg6ChangeI0aypGSgSvSgtFyycfU_ + 27
    10  WordPress                           0x00000001082b84a0 $sIeg_IeyB_TR + 48
    11  libdispatch.dylib                   0x00000001102f58ac _dispatch_call_block_and_release + 12
    12  libdispatch.dylib                   0x00000001102f6a88 _dispatch_client_callout + 8
    13  libdispatch.dylib                   0x0000000110304f23 _dispatch_main_queue_callback_4CF + 1152
    14  CoreFoundation                      0x00007fff203a8276 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    15  CoreFoundation                      0x00007fff203a2b06 __CFRunLoopRun + 2685
    16  CoreFoundation                      0x00007fff203a1b9e CFRunLoopRunSpecific + 567
    17  GraphicsServices                    0x00007fff2b773db3 GSEventRunModal + 139
    18  UIKitCore                           0x00007fff24660af3 -[UIApplication _run] + 912
    19  UIKitCore                           0x00007fff24665a04 UIApplicationMain + 101
    20  WordPress                           0x0000000108fb7734 main + 500
    21  libdyld.dylib                       0x00007fff20257415 start + 1
    22  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'nil is not a valid object ID'
terminating with uncaught exception of type NSException
CoreSimulator 732.17 - Device: iPhone 11 (1C390606-1277-4665-8DC6-27745C3935D4) - Runtime: iOS 14.0 (18A372) - DeviceType: iPhone 11
bummytime commented 4 years ago

Current impact: First Release: 15.3.0.3; 153 Users (5-20 events/day). I am removing the high-pri status from this issue. We will potentially add this issue to a "Media improvements" project starting in the near term.

diegoreymendez commented 4 years ago

The crashing code is from the backtrace is:

https://github.com/wordpress-mobile/WordPress-iOS/blob/b83aaaf67dc80e296871f805077ffc72accac018/WordPress/Classes/ViewRelated/Media/MediaProgressCoordinatorNoticeViewModel.swift#L159-L176

Some notes:

  1. We're obtaining blogInContext for the blog object, but the media object is accessed directly without checking what context it belongs to, or whether that context is appropriate for the current thread. According to CoreData's documentation, accessing media.blog is not safe if the context does not belong to the current thread.
  2. Since the crash happens in line 169, we can deduce in line 168 that blog.managedObjectContext != mainContext. Therefore the media object was not created in the main thread either. Following this logic we can also deduce that the media object was NOT created here (since the service instantiated here uses the main context) https://github.com/wordpress-mobile/WordPress-iOS/blob/develop/WordPress/Classes/Services/MediaCoordinator.swift#L160.
designsimply commented 3 years ago

@diegoreymendez looks like your PR knocked out https://github.com/wordpress-mobile/WordPress-iOS/issues/14960 but #14963 shows an increase in issues instead. Would you mind taking a quick look to see if anything stands out and then help let me know an estimate of time that you think it would take in order to investigate this one further? I feel it seems tricky since you already had one go at fixing it and the documentation of the steps to reproduce and the PR looked good to me. 🤔

Events in the last 90d: 1,100 Users affected in the last 90d: 729 WORDPRESS-IOS-38VR: https://sentry.io/share/issue/e8f83bc0ac2648e696b58ada13f6e31b/

image

stale[bot] commented 2 years ago

This issue has been marked as stale because:

Please comment with an update if you believe this issue is still valid or if it can be closed. This issue will also be reviewed for validity and priority during regularly scheduled triage sessions.