joeisapro / MonoTouch.Fabric

Xamarin.iOS Unified binding for Fabric
39 stars 9 forks source link

Setup.CaptureManagedInfo failing on iOS #5

Closed Ivan-L closed 8 years ago

Ivan-L commented 8 years ago

Hi there,

I believe we have hit an issue with MonoTouch.Fabric.Crashlytics when it tries to capture an UnobservedTaskException.

The following snippet is where the issue occurs, taken from the homepage:

TaskScheduler.UnobservedTaskException += (sender, e) =>
{
  Setup.CaptureManagedInfo(e.Exception);
  Setup.CaptureStackFrames(e.Exception);
  Setup.ThrowExceptionAsNative(e.Exception);
};

When an UnobservedTaskException occurs, Setup.CaptureManagedInfo is called, which results in the following error being logged on Crashlytics:

Fatal Exception: ArgumentNullException
0  ???  0x0 Foundation.NSString..ctor(String) (NSString.cs)
1  ???  0x0 MonoTouch.Fabric.Crashlytics.Setup.CaptureManagedInfo(System.Object) (Setup.cs)
2  ???  0x0 MyApp.iOS.AppDelegate+<>c.<FinishedLaunching>b__13_2(System.Object, System.Threading.Tasks.UnobservedTaskExceptionEventArgs) (<>c.cs)
3  ???  0x0 System.Threading.Tasks.TaskScheduler.PublishUnobservedTaskException(System.Object, System.Threading.Tasks.UnobservedTaskExceptionEventArgs) (TaskScheduler.cs)
4  ???  0x0 System.Threading.Tasks.TaskExceptionHolder.Finalize() (TaskExceptionHolder.cs)

Looking at the source code of the CaptureManagedInfo function, it constructs 3 NSString objects from the exception details:

Crashlytics.SharedInstance.SetObjectValue(new NSString(ex.StackTrace), "unhandled exception stack trace");
Crashlytics.SharedInstance.SetObjectValue(new NSString(ex.Message), "unhandled exception message");
Crashlytics.SharedInstance.SetObjectValue(new NSString(ex.GetType().FullName), "unhandled exception");

It appears that the ex.StackTrace might sometimes be null, which results in the real error details being masked by an exception being thrown by the CaptureManagedInfo function.

Is it possible to add a null check and only set the "unhandled exception stack trace" data if there actually is a stack trace?

joeisapro commented 8 years ago

Thanks for the report. Will update the package on NuGet as well.

Ivan-L commented 7 years ago

Thanks! The null check fixes the error and now we can see the real exception that occurred.

Here is what is logged in Crashlytics now (note that there is no stack trace for this particular exception):

Fatal Exception: AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.