sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

Reporting of unwrapping Optional value failure

Open martindufort opened this issue 2 years ago • 2 comments

Platform

macOS

Installed

CocoaPods

Version

7.9.0

Steps to Reproduce

In Swift, one of the most common exception / crash error we have seen in our app is this:

Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

However the sentry entry in the dashboard does not report this error with the above description. Any possibilities to update the description of this type of error so crash resolution is easier?

Test code to generate error:

var myQuestion: String!
print(myQuestion)

Thanks

Expected Result

The Sentry dashboard should be displaying:

Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

Actual Result

The Sentry Dashboard is currently displaying this information: EXC_BAD_INSTRUCTION value

martindufort avatar Feb 23 '22 14:02 martindufort

I can reproduce this issue in a release build. While I get the error message of calling fatalError directly, we don't get the error for unwrapping an optional value. The SDK is able to get the fatal error message in a debug build though. We added support for fatalError, assert, precondition with https://github.com/getsentry/sentry-cocoa/pull/1596. The fatal error message of implicitly unwrapping an Optional value doesn't end up in the crash_info_message of our crash reports generated by SentryCrash https://github.com/getsentry/sentry-cocoa/blob/cb117ceaf5bb343a72635e3079269185a75b09b8/Sources/Sentry/SentryCrashReportConverter.m#L469-L495

The crash report from Xcode doesn't add the optional value error message to the application specific information as it does for other fatal errors, see crash report below. Instead, we see the error message on the stack trace marked as inline.

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

...

Exception Type:  EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes: 0x0000000000000001, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Termination Reason: SIGNAL 4 Illegal instruction: 4
Terminating Process: exc handler [23208]

Triggered by Thread:  0

Application Specific Information:
CoreSimulator 783.5 - Device: iPhone 8 (6E9FC9E7-BCCE-4856-A817-31B671E63617) - Runtime: iOS 15.2 (19C51) - DeviceType: iPhone 8
dyld4 config: DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot
dyld4 config: DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot


Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   iOS-Swift                     	       0x104f3a1a2 Swift runtime failure: Unexpectedly found nil while unwrapping an Optional value + 0 [inlined]
1   iOS-Swift                     	       0x104f3a1a2 ViewController.optional() + 0 (ViewController.swift:63) [inlined]
2   iOS-Swift                     	       0x104f3a1a2 ViewController.optionalValue() + 0 (ViewController.swift:59) [inlined]
3   iOS-Swift                     	       0x104f3a1a2 ViewController.captureMessage(_:) + 0 (ViewController.swift:55) [inlined]
4   iOS-Swift                     	       0x104f3a1a2 @objc ViewController.captureMessage(_:) + 210 (<compiler-generated>:54)
5   UIKitCore                     	    0x7fff2506026d -[UIApplication sendAction:to:from:forEvent:] + 83
6   Sentry                        	       0x10563c94e __44-[SentryBreadcrumbTracker swizzleSendAction]_block_invoke_2 + 1045 (SentryBreadcrumbTracker.m:134)
7   UIKitCore                     	    0x7fff248f66e1 -[UIControl sendAction:to:forEvent:] + 110
8   UIKitCore                     	    0x7fff248f6ac3 -[UIControl _sendActionsForEvents:withEvent:] + 332
9   UIKitCore                     	    0x7fff248f2ffa -[UIButton _sendActionsForEvents:withEvent:] + 148
10  UIKitCore                     	    0x7fff248f5374 -[UIControl touchesEnded:withEvent:] + 488
11  UIKitCore                     	    0x7fff250a0c9d -[UIWindow _sendTouchesForEvent:] + 1287
12  UIKitCore                     	    0x7fff250a2d19 -[UIWindow sendEvent:] + 5289
13  UIKitCore                     	    0x7fff250795b6 -[UIApplication sendEvent:] + 819
14  UIKit                         	    0x7fff59ace03b -[UIApplicationAccessibility sendEvent:] + 85
15  UIKitCore                     	    0x7fff2510f4ef __dispatchPreprocessedEventFromEventQueue + 8683
16  UIKitCore                     	    0x7fff25111c75 __processEventQueue + 8579
17  UIKitCore                     	    0x7fff25108427 __eventFetcherSourceCallback + 240
18  CoreFoundation                	    0x7fff2036ce15 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
19  CoreFoundation                	    0x7fff2036cd0d __CFRunLoopDoSource0 + 180
20  CoreFoundation                	    0x7fff2036c1e2 __CFRunLoopDoSources0 + 242
21  CoreFoundation                	    0x7fff20366941 __CFRunLoopRun + 875
22  CoreFoundation                	    0x7fff203660f3 CFRunLoopRunSpecific + 567
23  GraphicsServices              	    0x7fff2c995cd3 GSEventRunModal + 139
24  UIKitCore                     	    0x7fff25059f42 -[UIApplication _run] + 928
25  UIKitCore                     	    0x7fff2505eb5e UIApplicationMain + 101
26  iOS-Swift                     	       0x104f386ba main + 58 (AppDelegate.swift:5)
27  dyld_sim                      	       0x10518cee9 start_sim + 10
28  dyld                          	       0x10af114fe start + 462
-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

...

Exception Type:  EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes: 0x0000000000000001, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Termination Reason: SIGNAL 4 Illegal instruction: 4
Terminating Process: exc handler [23332]

Triggered by Thread:  0

Application Specific Information:
dyld4 config: DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot
CoreSimulator 783.5 - Device: iPhone 8 (6E9FC9E7-BCCE-4856-A817-31B671E63617) - Runtime: iOS 15.2 (19C51) - DeviceType: iPhone 8
iOS_Swift/ViewController.swift:106: Fatal error: This is a fatal error. Oh no 😬.
dyld4 config: DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot


Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libswiftCore.dylib            	    0x7fff3073ff1b _assertionFailure(_:_:file:line:flags:) + 427
1   iOS-Swift                     	       0x10eca8419 ViewController.captureFatalError(_:) + 67 (ViewController.swift:106) [inlined]
2   iOS-Swift                     	       0x10eca8419 @objc ViewController.captureFatalError(_:) + 105 (<compiler-generated>:105)
3   UIKitCore                     	    0x7fff2506026d -[UIApplication sendAction:to:from:forEvent:] + 83
4   Sentry                        	       0x10f3aa94e __44-[SentryBreadcrumbTracker swizzleSendAction]_block_invoke_2 + 1045 (SentryBreadcrumbTracker.m:134)
5   UIKitCore                     	    0x7fff248f66e1 -[UIControl sendAction:to:forEvent:] + 110
6   UIKitCore                     	    0x7fff248f6ac3 -[UIControl _sendActionsForEvents:withEvent:] + 332
7   UIKitCore                     	    0x7fff248f2ffa -[UIButton _sendActionsForEvents:withEvent:] + 148
8   UIKitCore                     	    0x7fff248f5374 -[UIControl touchesEnded:withEvent:] + 488
9   UIKitCore                     	    0x7fff250a0c9d -[UIWindow _sendTouchesForEvent:] + 1287
10  UIKitCore                     	    0x7fff250a2d19 -[UIWindow sendEvent:] + 5289
11  UIKitCore                     	    0x7fff250795b6 -[UIApplication sendEvent:] + 819
12  UIKit                         	    0x7fff59ace03b -[UIApplicationAccessibility sendEvent:] + 85
13  UIKitCore                     	    0x7fff2510f4ef __dispatchPreprocessedEventFromEventQueue + 8683
14  UIKitCore                     	    0x7fff25111c75 __processEventQueue + 8579
15  UIKitCore                     	    0x7fff25108427 __eventFetcherSourceCallback + 240
16  CoreFoundation                	    0x7fff2036ce15 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17  CoreFoundation                	    0x7fff2036cd0d __CFRunLoopDoSource0 + 180
18  CoreFoundation                	    0x7fff2036c1e2 __CFRunLoopDoSources0 + 242
19  CoreFoundation                	    0x7fff20366941 __CFRunLoopRun + 875
20  CoreFoundation                	    0x7fff203660f3 CFRunLoopRunSpecific + 567
21  GraphicsServices              	    0x7fff2c995cd3 GSEventRunModal + 139
22  UIKitCore                     	    0x7fff25059f42 -[UIApplication _run] + 928
23  UIKitCore                     	    0x7fff2505eb5e UIApplicationMain + 101
24  iOS-Swift                     	       0x10eca66ba main + 58 (AppDelegate.swift:5)
25  dyld_sim                      	       0x10eefaee9 start_sim + 10
26  dyld                          	       0x117cee4fe start + 462

It could be that we have a bug in here https://github.com/getsentry/sentry-cocoa/blob/cb117ceaf5bb343a72635e3079269185a75b09b8/Sources/SentryCrash/Recording/Tools/SentryCrashDynamicLinker.c#L296

philipphofmann avatar Mar 01 '22 09:03 philipphofmann

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Mar 23 '22 00:03 github-actions[bot]

preconditionFailure messages also don't get reported in release builds. I suspect the root cause is the same as this issue.

shadowfacts avatar Oct 30 '22 15:10 shadowfacts

preconditionFailure messages also don't get reported in release builds. I suspect the root cause is the same as this issue.

It could be related, yes, @shadowfacts. Thanks for the update.

philipphofmann avatar Nov 02 '22 18:11 philipphofmann

I've added a force unwrap crash to our sample project, and I am seeing it reported as expected in Sentry.

Screenshot 2022-11-30 at 09 45 58

Screenshot 2022-11-30 at 09 43 58

https://sentry.io/organizations/sentry-sdks/issues/3777433434/?project=5428557&query=is%3Aunresolved&referrer=issue-stream

So I am not sure what the problem is?

kevinrenskers avatar Nov 30 '22 08:11 kevinrenskers

@martindufort, can you please check https://github.com/getsentry/sentry-cocoa/issues/1667#issuecomment-1331819969. The feature should work correctly.

philipphofmann avatar Dec 01 '22 13:12 philipphofmann

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Jan 13 '23 00:01 github-actions[bot]

@martindufort, as pointed out above, the feature should work correctly. Please reopen the issue with more details if it doesn't work.

philipphofmann avatar Jan 17 '23 07:01 philipphofmann