11using System ;
22using System . Collections . Generic ;
33using System . IO ;
4+ using System . Runtime . InteropServices . ComTypes ;
5+ using Sentry . Extensibility ;
46using Sentry . Protocol ;
57using UnityEngine ;
68
@@ -20,18 +22,14 @@ internal class UnityErrorLogException : Exception
2022 private readonly string _logStackTrace = string . Empty ;
2123
2224 private readonly SentryOptions ? _options ;
25+ private readonly IDiagnosticLogger ? _logger ;
2326
2427 public UnityErrorLogException ( string logString , string logStackTrace , SentryOptions ? options )
2528 {
2629 _logString = logString ;
2730 _logStackTrace = logStackTrace ;
2831 _options = options ;
29- }
30-
31- internal UnityErrorLogException ( string logString , string logStackTrace )
32- {
33- _logString = logString ;
34- _logStackTrace = logStackTrace ;
32+ _logger = _options ? . DiagnosticLogger ;
3533 }
3634
3735 internal UnityErrorLogException ( ) : base ( ) { }
@@ -42,6 +40,8 @@ private UnityErrorLogException(string message, Exception innerException) : base(
4240
4341 public SentryException ToSentryException ( )
4442 {
43+ _logger ? . LogDebug ( "Creating SentryException out of synthetic ErrorLogException" ) ;
44+
4545 var frames = ParseStackTrace ( _logStackTrace ) ;
4646 frames . Reverse ( ) ;
4747
@@ -80,7 +80,7 @@ private List<SentryStackFrame> ParseStackTrace(string stackTrace)
8080 continue ;
8181 }
8282
83- var frame = ParseStackFrame ( item ) ;
83+ var frame = ParseStackFrame ( item , _logger ) ;
8484 if ( _options is not null )
8585 {
8686 frame . ConfigureAppFrame ( _options ) ;
@@ -91,7 +91,7 @@ private List<SentryStackFrame> ParseStackTrace(string stackTrace)
9191 return frames ;
9292 }
9393
94- private static SentryStackFrame ParseStackFrame ( string stackFrameLine )
94+ private static SentryStackFrame ParseStackFrame ( string stackFrameLine , IDiagnosticLogger ? logger = null )
9595 {
9696 var closingParenthesis = stackFrameLine . IndexOf ( ')' ) ;
9797 if ( closingParenthesis == - 1 )
@@ -121,8 +121,10 @@ private static SentryStackFrame ParseStackFrame(string stackFrameLine)
121121 LineNumber = lineNo == - 1 ? null : lineNo
122122 } ;
123123 }
124- catch ( Exception )
124+ catch ( Exception e )
125125 {
126+ logger ? . LogError ( e , "Failed to parse the stack frame line {0}" , stackFrameLine ) ;
127+
126128 // Suppress any errors while parsing and fall back to a basic stackframe
127129 return CreateBasicStackFrame ( stackFrameLine ) ;
128130 }
0 commit comments