Skip to content

Commit 6573fbc

Browse files
authored
Fix/parsing logging (#1992)
1 parent 1351039 commit 6573fbc

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/Sentry.Unity/Integrations/UnityErrorLogException.cs

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using Sentry.Extensibility;
45
using Sentry.Protocol;
56
using UnityEngine;
67

@@ -20,18 +21,14 @@ internal class UnityErrorLogException : Exception
2021
private readonly string _logStackTrace = string.Empty;
2122

2223
private readonly SentryOptions? _options;
24+
private readonly IDiagnosticLogger? _logger;
2325

2426
public UnityErrorLogException(string logString, string logStackTrace, SentryOptions? options)
2527
{
2628
_logString = logString;
2729
_logStackTrace = logStackTrace;
2830
_options = options;
29-
}
30-
31-
internal UnityErrorLogException(string logString, string logStackTrace)
32-
{
33-
_logString = logString;
34-
_logStackTrace = logStackTrace;
31+
_logger = _options?.DiagnosticLogger;
3532
}
3633

3734
internal UnityErrorLogException() : base() { }
@@ -42,6 +39,8 @@ private UnityErrorLogException(string message, Exception innerException) : base(
4239

4340
public SentryException ToSentryException()
4441
{
42+
_logger?.LogDebug("Creating SentryException out of synthetic ErrorLogException");
43+
4544
var frames = ParseStackTrace(_logStackTrace);
4645
frames.Reverse();
4746

@@ -80,7 +79,7 @@ private List<SentryStackFrame> ParseStackTrace(string stackTrace)
8079
continue;
8180
}
8281

83-
var frame = ParseStackFrame(item);
82+
var frame = ParseStackFrame(item, _logger);
8483
if (_options is not null)
8584
{
8685
frame.ConfigureAppFrame(_options);
@@ -91,7 +90,7 @@ private List<SentryStackFrame> ParseStackTrace(string stackTrace)
9190
return frames;
9291
}
9392

94-
private static SentryStackFrame ParseStackFrame(string stackFrameLine)
93+
private static SentryStackFrame ParseStackFrame(string stackFrameLine, IDiagnosticLogger? logger = null)
9594
{
9695
var closingParenthesis = stackFrameLine.IndexOf(')');
9796
if (closingParenthesis == -1)
@@ -121,8 +120,10 @@ private static SentryStackFrame ParseStackFrame(string stackFrameLine)
121120
LineNumber = lineNo == -1 ? null : lineNo
122121
};
123122
}
124-
catch (Exception)
123+
catch (Exception e)
125124
{
125+
logger?.LogError(e, "Failed to parse the stack frame line {0}", stackFrameLine);
126+
126127
// Suppress any errors while parsing and fall back to a basic stackframe
127128
return CreateBasicStackFrame(stackFrameLine);
128129
}

0 commit comments

Comments
 (0)