Skip to content

Commit

Permalink
Merge pull request #140 from bugsnag/yousif/fix-null-methodname-crash
Browse files Browse the repository at this point in the history
Fix crash when stackframe method is null
  • Loading branch information
yousif-bugsnag committed Jul 19, 2021
2 parents ee12213 + 3c64b18 commit 371702b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/Bugsnag/Middleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,17 @@ public static class InternalMiddleware
{
foreach (var stackTraceLine in exception.StackTrace)
{
foreach (var @namespace in report.Configuration.ProjectNamespaces)
if (!Polyfills.String.IsNullOrWhiteSpace(stackTraceLine.MethodName))
{
if (stackTraceLine.MethodName.StartsWith(@namespace))
foreach (var @namespace in report.Configuration.ProjectNamespaces)
{
stackTraceLine.InProject = true;
break;
if (stackTraceLine.MethodName.StartsWith(@namespace))
{
stackTraceLine.InProject = true;
break;
}
}
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bugsnag/Payload/StackTraceLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public IEnumerator<StackTraceLine> GetEnumerator()
{
// if the exception has not come from a stack trace then we need to
// skip the frames that originate from inside the notifier code base
var currentStackFrameIsNotify = stackFrame.MethodName.StartsWith("Bugsnag.Client.Notify");
var currentStackFrameIsNotify = !Polyfills.String.IsNullOrWhiteSpace(stackFrame.MethodName) && stackFrame.MethodName.StartsWith("Bugsnag.Client.Notify");
seenBugsnagFrames = seenBugsnagFrames || currentStackFrameIsNotify;
if (!seenBugsnagFrames || currentStackFrameIsNotify)
{
Expand Down
8 changes: 8 additions & 0 deletions tests/Bugsnag.Tests/MiddlewareTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ public static IEnumerable<object[]> InProjectTestData()
ShouldBeMarkedAsInProject = true }
}
};
yield return new object[] {
new string[] { "Bugsnag.Code", "Bugsnag.Assets" },
new StackTraceInProjectTestCase[] {
new StackTraceInProjectTestCase {
MethodName = null,
ShouldBeMarkedAsInProject = false }
}
};
}
}
}

0 comments on commit 371702b

Please sign in to comment.