Skip to content

Commit 99b84e9

Browse files
committed
feat: Use the first frame of a stacktrace to guess for broken assemblies
1 parent 5d7a6df commit 99b84e9

File tree

1 file changed

+52
-15
lines changed

1 file changed

+52
-15
lines changed

src/UnityDebuggerAssistant/Processing/UDAExceptionHandler.cs

+52-15
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,55 @@ public static void Handle(Exception ex)
2020
var targets = ex.TargetSite;
2121
var trace = new StackTrace(ex, true);
2222
var assembly = targets?.DeclaringType.Assembly;
23+
bool guessed = false;
2324

24-
//Filter the main assembly
25-
if (assembly is not null)
26-
if (!UDAWhitelist.IsOnExceptionWhitelist(assembly) || UDABlacklist.IsOnExceptionBlacklist(assembly))
25+
if (assembly is null)
26+
{
27+
guessed = true;
28+
29+
if (trace.FrameCount == 0)
30+
{
31+
#if DEBUG
32+
UDAPlugin.Log?.LogInfo($"Skipping {ex.GetType()}, trace has no frames");
33+
return;
34+
#endif
35+
}
36+
37+
foreach (var item in trace.GetFrames())
38+
{
39+
if (item.HasMethod())
40+
{
41+
assembly = item.GetMethod().DeclaringType.Assembly;
42+
break;
43+
}
44+
}
45+
46+
if (assembly is null)
2747
{
2848
#if DEBUG
29-
UDAPlugin.Log?.LogInfo($"Skipping {assembly.GetName().Name}, failed filter");
49+
UDAPlugin.Log?.LogInfo($"Skipping {ex.GetType()}, unable to obtain assembly info");
3050
#endif
51+
3152
return;
3253
}
54+
#if DEBUG
55+
else
56+
{
57+
58+
UDAPlugin.Log?.LogInfo($"Guessing {ex.GetType()}'s assembly");
59+
60+
}
61+
#endif
62+
}
63+
64+
//Filter the main assembly
65+
if (!UDAWhitelist.IsOnExceptionWhitelist(assembly) || UDABlacklist.IsOnExceptionBlacklist(assembly))
66+
{
67+
#if DEBUG
68+
UDAPlugin.Log?.LogInfo($"Skipping {assembly.GetName().Name}, failed filter");
69+
#endif
70+
return;
71+
}
3372

3473
static string Tabs(int n)
3574
{
@@ -172,21 +211,19 @@ static void DoHarmonyBlames(StringBuilder sb, ReadOnlyCollection<Patch>? Patches
172211
sb.AppendLine(ex.GetType().ToString());
173212

174213
sb.Append("Assembly: ");
175-
if (assembly is not null)
214+
sb.Append(assembly.GetName().Name);
215+
216+
if (guessed)
176217
{
177-
sb.AppendLine(assembly.GetName().Name);
218+
sb.Append(" (Guess)");
178219
}
179-
else
180-
{
181-
sb.AppendLine("Unknown");
182220

183-
}
221+
sb.AppendLine();
184222

185-
if (assembly is not null)
186-
if (UDAPluginMarshal.InfoCache.TryGetValue(assembly, out PluginInfo info))
187-
{
188-
WritePluginInfo(sb, info, 1);
189-
}
223+
if (UDAPluginMarshal.InfoCache.TryGetValue(assembly, out PluginInfo info))
224+
{
225+
WritePluginInfo(sb, info, 1);
226+
}
190227

191228
sb.Append("Message: ");
192229
sb.AppendLine(ex.Message);

0 commit comments

Comments
 (0)