Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define "[file]" in one place only #63

Merged
merged 1 commit into from
Jul 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Bugsnag.NET.Tests/StacktracelineParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class StacktracelineParsingTests
readonly string _asyncAwaitPreviousLocationLine = @"--- End of stack trace from previous location where exception was thrown ---";

readonly string _parseFailedMethodName = "[method]";
readonly string _parseFailedFile = "[file]";
readonly string _parseFailedFile = CommonExtensions.FileParseFailureDefaultValue;
readonly int _parseFailedLineNumber = -1;

[Test]
Expand Down
7 changes: 4 additions & 3 deletions Bugsnag.NET/StackTraceLineHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bugsnag.Common;
using Bugsnag.Common.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -10,9 +11,9 @@ namespace Bugsnag.NET
{
public static class StackTraceLineHelper
{
const string _defaultFileValue = "[file]";
static string _DefaultFileValue => CommonExtensions.FileParseFailureDefaultValue;

public static bool HasSuccessfullyParsedFile(this IStackTraceLine line) => line?.File != _defaultFileValue;
public static bool HasSuccessfullyParsedFile(this IStackTraceLine line) => line?.File != _DefaultFileValue;

public static bool IsFromNamespaces(
this IStackTraceLine line,
Expand All @@ -21,7 +22,7 @@ public static bool IsFromNamespaces(
public static string TryGetTrimmedFile(this IStackTraceLine line, Regex regex) => line.TryGetTrimmedFile(regex, str => str);
public static string TryGetTrimmedFile(this IStackTraceLine line, Regex regex, Func<string, string> additionalTransformOnSuccess)
{
var fileName = line?.File ?? _defaultFileValue; // NOTE: Not sure if a better thing here to coerce or just blow up
var fileName = line?.File ?? _DefaultFileValue; // NOTE: Not sure if a better thing here to coerce or just blow up
var match = regex.Match(fileName);

return match.Success
Expand Down
4 changes: 3 additions & 1 deletion lib/Bugsnag.Common/Extensions/CommonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ public static IEnumerable<string> ToLines(this Exception ex)
);
}

public static string FileParseFailureDefaultValue = "[file]";

public static string ParseFile(this string line)
{
var match = Regex.Match(line, "in (.+):line");
if (match.Groups.Count < 2) { return "[file]"; }
if (match.Groups.Count < 2) { return FileParseFailureDefaultValue; }

return match.Groups[1].Value;
}
Expand Down