Skip to content

Commit 3aff70c

Browse files
committed
added logs to 'tosentryexception'
1 parent 1351039 commit 3aff70c

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/Sentry.Unity/Integrations/UnityErrorLogException.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Runtime.InteropServices.ComTypes;
5+
using Sentry.Extensibility;
46
using Sentry.Protocol;
57
using 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

Comments
 (0)