17 using System.Text.RegularExpressions;
26 private static Regex FileAndLineRegex =
new (
"(\\w+.cs:line \\d+)", RegexOptions.Compiled);
31 public virtual int Order =>
int.MaxValue;
38 public virtual bool CanInterpret(Exception exception) =>
true;
48 var sanitized =
new SanitizedException(exception.Message, exception.StackTrace);
54 return new Exception(exception.Message + fileAndLine, innerException: sanitized);
63 if (stackTrace !=
null)
65 var match = FileAndLineRegex.Match(stackTrace);
68 foreach (Match lineCapture
in match.Captures)
70 fileAndLine = $
" in {lineCapture.Groups[1].Value}" ;
78 private class SanitizedException : Exception
80 private readonly
string _message;
81 private readonly
string _stackTrace;
83 public override string Message => _message;
84 public override string StackTrace => _stackTrace;
86 public SanitizedException(
string message,
string stackTrace)
89 _stackTrace = Logging.Log.ClearLeanPaths(stackTrace);