1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
+ using Sentry . Extensibility ;
4
5
using Sentry . Protocol ;
5
6
using UnityEngine ;
6
7
@@ -20,18 +21,14 @@ internal class UnityErrorLogException : Exception
20
21
private readonly string _logStackTrace = string . Empty ;
21
22
22
23
private readonly SentryOptions ? _options ;
24
+ private readonly IDiagnosticLogger ? _logger ;
23
25
24
26
public UnityErrorLogException ( string logString , string logStackTrace , SentryOptions ? options )
25
27
{
26
28
_logString = logString ;
27
29
_logStackTrace = logStackTrace ;
28
30
_options = options ;
29
- }
30
-
31
- internal UnityErrorLogException ( string logString , string logStackTrace )
32
- {
33
- _logString = logString ;
34
- _logStackTrace = logStackTrace ;
31
+ _logger = _options ? . DiagnosticLogger ;
35
32
}
36
33
37
34
internal UnityErrorLogException ( ) : base ( ) { }
@@ -42,6 +39,8 @@ private UnityErrorLogException(string message, Exception innerException) : base(
42
39
43
40
public SentryException ToSentryException ( )
44
41
{
42
+ _logger ? . LogDebug ( "Creating SentryException out of synthetic ErrorLogException" ) ;
43
+
45
44
var frames = ParseStackTrace ( _logStackTrace ) ;
46
45
frames . Reverse ( ) ;
47
46
@@ -80,7 +79,7 @@ private List<SentryStackFrame> ParseStackTrace(string stackTrace)
80
79
continue ;
81
80
}
82
81
83
- var frame = ParseStackFrame ( item ) ;
82
+ var frame = ParseStackFrame ( item , _logger ) ;
84
83
if ( _options is not null )
85
84
{
86
85
frame . ConfigureAppFrame ( _options ) ;
@@ -91,7 +90,7 @@ private List<SentryStackFrame> ParseStackTrace(string stackTrace)
91
90
return frames ;
92
91
}
93
92
94
- private static SentryStackFrame ParseStackFrame ( string stackFrameLine )
93
+ private static SentryStackFrame ParseStackFrame ( string stackFrameLine , IDiagnosticLogger ? logger = null )
95
94
{
96
95
var closingParenthesis = stackFrameLine . IndexOf ( ')' ) ;
97
96
if ( closingParenthesis == - 1 )
@@ -121,8 +120,10 @@ private static SentryStackFrame ParseStackFrame(string stackFrameLine)
121
120
LineNumber = lineNo == - 1 ? null : lineNo
122
121
} ;
123
122
}
124
- catch ( Exception )
123
+ catch ( Exception e )
125
124
{
125
+ logger ? . LogError ( e , "Failed to parse the stack frame line {0}" , stackFrameLine ) ;
126
+
126
127
// Suppress any errors while parsing and fall back to a basic stackframe
127
128
return CreateBasicStackFrame ( stackFrameLine ) ;
128
129
}
0 commit comments