getsentry / sentry-dotnet

Sentry SDK for .NET
https://docs.sentry.io/platforms/dotnet
MIT License
582 stars 206 forks source link

ArgumentNullException at Regex.Match while trying to capture exception #64

Closed vplme closed 6 years ago

vplme commented 6 years ago

Hi,

I'm trying to test out Sentry with Xamarin Forms but I was not getting any logs back in Sentry from unhandled exceptions in my Xamarin Forms app. Capturing regular exceptions works fine (e.g. SentrySdk.CaptureException(new Exception("Testing"))

So I tried using my own UnhandledException handler but it seems like I'm getting an exception while trying to call SentrySdk.CaptureException(exception)? Which might be the original reason why I didn't get any unhandled exceptions via default Sentry handler (AppDomainUnhandledExceptionIntegration)

iOS unhandled exception code:

public class Application
    {
        // This is the main entry point of the application.
        static void Main(string[] args)
        {
            // if you want to use a different Application Delegate class from "AppDelegate"
            // you can specify it here.
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            UIApplication.Main(args, null, "AppDelegate");

        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Console.WriteLine("Exception is unhandled");
            Exception exception = e.ExceptionObject as Exception;
            try
            {
                SentrySdk.CaptureException(exception); // This results in an ArgumentNullException
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
            }
        }

Exception I got from the try catch while trying to CaptureException:

2018-07-26 13:15:12.677512+0200 MyApp.iOS[42004:3175540] System.ArgumentNullException: Value cannot be null.
Parameter name: input
  at System.Text.RegularExpressions.Regex.Match (System.String input) [0x00003] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.99.1.44/src/Xamarin.iOS/mcs/class/referencesource/System/regex/system/text/regularexpressions/Regex.cs:862 
  at System.Text.RegularExpressions.Regex.Match (System.String input, System.String pattern, System.Text.RegularExpressions.RegexOptions options, System.TimeSpan matchTimeout) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.99.1.44/src/Xamarin.iOS/mcs/class/referencesource/System/regex/system/text/regularexpressions/Regex.cs:846 
  at System.Text.RegularExpressions.Regex.Match (System.String input, System.String pattern) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.99.1.44/src/Xamarin.iOS/mcs/class/referencesource/System/regex/system/text/regularexpressions/Regex.cs:822 
  at Sentry.Internal.MainExceptionProcessor.DemangleAnonymousFunction (Sentry.Protocol.SentryStackFrame frame) [0x00004] in C:\projects\sentry-dotnet\src\Sentry\Internal\MainExceptionProcessor.cs:218 
  at Sentry.Internal.MainExceptionProcessor.CreateSentryStackFrame (System.Diagnostics.StackFrame stackFrame) [0x000d7] in C:\projects\sentry-dotnet\src\Sentry\Internal\MainExceptionProcessor.cs:157 
  at System.Linq.Enumerable+SelectEnumerableIterator`2[TSource,TResult].ToList () [0x0001b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.99.1.44/src/Xamarin.iOS/external/corefx/src/System.Linq/src/System/Linq/Select.cs:163 
  at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.99.1.44/src/Xamarin.iOS/external/corefx/src/System.Linq/src/System/Linq/ToCollection.cs:30 
  at Sentry.Internal.MainExceptionProcessor+<CreateSentryException>d__1.MoveNext () [0x00236] in C:\projects\sentry-dotnet\src\Sentry\Internal\MainExceptionProcessor.cs:85 
  at System.Collections.Generic.List`1[T]..ctor (System.Collections.Generic.IEnumerable`1[T] collection) [0x00077] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.99.1.44/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/collections/generic/list.cs:99 
  at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.99.1.44/src/Xamarin.iOS/external/corefx/src/System.Linq/src/System/Linq/ToCollection.cs:30 
  at Sentry.Internal.MainExceptionProcessor.Process (System.Exception exception, Sentry.SentryEvent sentryEvent) [0x00006] in C:\projects\sentry-dotnet\src\Sentry\Internal\MainExceptionProcessor.cs:22 
  at Sentry.Internal.MainSentryEventProcessor.Process (Sentry.SentryEvent event) [0x0010d] in C:\projects\sentry-dotnet\src\Sentry\Internal\MainSentryEventProcessor.cs:82 
  at Sentry.SentryClient.CaptureEvent (Sentry.SentryEvent event, Sentry.Protocol.Scope scope) [0x0004a] in C:\projects\sentry-dotnet\src\Sentry\SentryClient.cs:85 
  at Sentry.Internal.Hub.CaptureEvent (Sentry.SentryEvent evt, Sentry.Protocol.Scope scope) [0x00017] in C:\projects\sentry-dotnet\src\Sentry\Internal\Hub.cs:54 
  at Sentry.SentryClientExtensions.CaptureException (Sentry.ISentryClient client, System.Exception ex) [0x00000] in C:\projects\sentry-dotnet\src\Sentry\SentryClientExtensions.cs:21 
  at Sentry.SentrySdk.CaptureException (System.Exception exception) [0x00000] in C:\projects\sentry-dotnet\src\Sentry\SentrySdk.cs:258 
  at MyApp.iOS.Application.CurrentDomain_UnhandledException (System.Object sender, System.UnhandledExceptionEventArgs e) [0x00019] in /Users/vpl/Repos/MyApp-app/src/MyApp.iOS/Main.cs:26
2018-07-26 13:15:12.679037+0200 MyApp.iOS[42004:3175540] warning: exception inside UnhandledException handler: Value cannot be null.

Exception I was trying to capture:

2018-07-26 13:15:12.680053+0200 MyApp.iOS[42004:3175540] Unhandled managed exception:
Object reference not set to an instance of an object (System.NullReferenceException)
  at MyApp.SettingsViewModel.<.ctor>b__5_10 () [0x00001] in /Users/vpl/Repos/MyApp-app/src/MyApp.Shared/ViewModels/SettingsViewModel.cs:178 
  at Xamarin.Forms.Command+<>c__DisplayClass3_0.<.ctor>b__0 (System.Object o) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Command.cs:73 
  at Xamarin.Forms.Command.Execute (System.Object parameter) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Command.cs:107 
  at Xamarin.Forms.TextCell.OnTapped () [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Cells\TextCell.cs:89 
  at Xamarin.Forms.TableView+TableSectionModel.OnRowSelected (System.Object item) [0x00007] in D:\a\1\s\Xamarin.Forms.Core\TableView.cs:212 
  at Xamarin.Forms.Internals.TableModel.RowSelected (System.Object item) [0x0001a] in D:\a\1\s\Xamarin.Forms.Core\TableModel.cs:68 
  at Xamarin.Forms.Internals.TableModel.RowSelected (System.Int32 section, System.Int32 row) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\TableModel.cs:60 
  at Xamarin.Forms.Platform.iOS.TableViewModelRenderer.RowSelected (UIKit.UITableView tableView, Foundation.NSIndexPath indexPath) [0x00017] in <2a59efab866341818ab4748ebe270f0a>:0 
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.99.1.44/src/Xamarin.iOS/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.99.1.44/src/Xamarin.iOS/UIKit/UIApplication.cs:63 
  at MyApp.iOS.Application.Main (System.String[] args) [0x00018] in /Users/vpl/Repos/MyApp-app/src/MyApp.iOS/Main.cs:16
2018-07-26 13:15:12.680325+0200 MyApp.iOS[42004:3175540] critical: Stacktrace:
2018-07-26 13:15:12.680415+0200 MyApp.iOS[42004:3175540] critical: 
Native stacktrace:
2018-07-26 13:15:12.688255+0200 MyApp.iOS[42004:3175540] critical:  0   MyApp.iOS                            0x00000001022ad1d4 mono_handle_native_crash + 244
2018-07-26 13:15:12.688399+0200 MyApp.iOS[42004:3175540] critical:  1   libsystem_platform.dylib            0x00000001126c9f5a _sigtramp + 26
2018-07-26 13:15:12.688504+0200 MyApp.iOS[42004:3175540] critical:  2   ???                                 0x00000001029ec12c 0x0 + 4338925868
2018-07-26 13:15:12.688629+0200 MyApp.iOS[42004:3175540] critical:  3   libsystem_c.dylib                   0x0000000112452b81 abort + 127
2018-07-26 13:15:12.688744+0200 MyApp.iOS[42004:3175540] critical:  4   MyApp.iOS                            0x00000001024b667f xamarin_unhandled_exception_handler + 47
2018-07-26 13:15:12.688856+0200 MyApp.iOS[42004:3175540] critical:  5   MyApp.iOS                            0x000000010233a434 mono_invoke_unhandled_exception_hook + 148
2018-07-26 13:15:12.688996+0200 MyApp.iOS[42004:3175540] critical:  6   MyApp.iOS                            0x00000001022acc89 mono_handle_exception_internal + 6105
2018-07-26 13:15:12.689135+0200 MyApp.iOS[42004:3175540] critical:  7   MyApp.iOS                            0x00000001022ab4a9 mono_handle_exception + 25
2018-07-26 13:15:12.689257+0200 MyApp.iOS[42004:3175540] critical:  8   MyApp.iOS                            0x00000001022169df mono_amd64_throw_exception + 143
2018-07-26 13:15:12.689390+0200 MyApp.iOS[42004:3175540] critical:  9   ???                                 0x000000013132a827 0x0 + 5120370727
2018-07-26 13:15:12.689499+0200 MyApp.iOS[42004:3175540] critical:  10  MyApp.iOS                            0x00000001022bf6d3 mono_jit_runtime_invoke + 1443
2018-07-26 13:15:12.689648+0200 MyApp.iOS[42004:3175540] critical:  11  MyApp.iOS                            0x000000010239e80f mono_runtime_invoke_checked + 127
2018-07-26 13:15:12.689774+0200 MyApp.iOS[42004:3175540] critical:  12  MyApp.iOS                            0x00000001023a210c mono_runtime_invoke + 76
2018-07-26 13:15:12.689881+0200 MyApp.iOS[42004:3175540] critical:  13  MyApp.iOS                            0x00000001024bfb0e xamarin_invoke_trampoline + 6046
2018-07-26 13:15:12.689979+0200 MyApp.iOS[42004:3175540] critical:  14  MyApp.iOS                            0x00000001024c7fed xamarin_arch_trampoline + 189
2018-07-26 13:15:12.690087+0200 MyApp.iOS[42004:3175540] critical:  15  MyApp.iOS                            0x00000001024c9421 xamarin_x86_64_common_trampoline + 110
2018-07-26 13:15:12.690183+0200 MyApp.iOS[42004:3175540] critical:  16  UIKitCore                           0x000000011a4def71 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1813
2018-07-26 13:15:12.690292+0200 MyApp.iOS[42004:3175540] critical:  17  UIKitCore                           0x000000011a4df18c -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 344
2018-07-26 13:15:12.690432+0200 MyApp.iOS[42004:3175540] critical:  18  UIKitCore                           0x0000000119f9bdb5 _runAfterCACommitDeferredBlocks + 318
2018-07-26 13:15:12.690561+0200 MyApp.iOS[42004:3175540] critical:  19  UIKitCore                           0x0000000119f8ac0b _cleanUpAfterCAFlushAndRunDeferredBlocks + 397
2018-07-26 13:15:12.690663+0200 MyApp.iOS[42004:3175540] critical:  20  UIKitCore                           0x0000000119fba5e7 _afterCACommitHandler + 141
2018-07-26 13:15:12.690832+0200 MyApp.iOS[42004:3175540] critical:  21  CoreFoundation                      0x0000000110094ea7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
2018-07-26 13:15:12.691011+0200 MyApp.iOS[42004:3175540] critical:  22  CoreFoundation                      0x000000011008f2de __CFRunLoopDoObservers + 430
2018-07-26 13:15:12.691151+0200 MyApp.iOS[42004:3175540] critical:  23  CoreFoundation                      0x000000011008f981 __CFRunLoopRun + 1553
2018-07-26 13:15:12.691304+0200 MyApp.iOS[42004:3175540] critical:  24  CoreFoundation                      0x000000011008f031 CFRunLoopRunSpecific + 625
2018-07-26 13:15:12.691484+0200 MyApp.iOS[42004:3175540] critical:  25  GraphicsServices                    0x00000001162ce136 GSEventRunModal + 62
2018-07-26 13:15:12.691648+0200 MyApp.iOS[42004:3175540] critical:  26  UIKitCore                           0x0000000119f90839 UIApplicationMain + 140
2018-07-26 13:15:12.691807+0200 MyApp.iOS[42004:3175540] critical:  27  ???                                 0x000000013543b287 0x0 + 5188596359
2018-07-26 13:15:12.691983+0200 MyApp.iOS[42004:3175540] critical:  28  ???                                 0x000000013543afe3 0x0 + 5188595683
2018-07-26 13:15:12.692140+0200 MyApp.iOS[42004:3175540] critical: 
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
bruno-garcia commented 6 years ago

@vverst Thanks a lot for trying the SDK and reporting this issue! With all the info you provided it was quick to spot the error.

We'll be making sure the SDK doesn't throw before we release a final version. At this point I belive it's better to have feedback so we can fix these issues quickly before the first release.

vplme commented 6 years ago

Thank you for the quick response! That is great to hear :smile:

bruno-garcia commented 6 years ago

@vverst A new version with the fix was published:

https://github.com/getsentry/sentry-dotnet/releases/tag/0.0.1-preview4

Thanks again for helping trying it out and reporting!