Skip to content

Commit

Permalink
Format stacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
JaneySprings committed Nov 19, 2024
1 parent 25900d0 commit 31e97ad
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/DotNet.Meteor.Debug/Extensions/ServerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using DotNet.Meteor.Common;
using Mono.Debugging.Soft;
using System.Text.Json.Serialization;
using System.Text;

namespace DotNet.Meteor.Debug.Extensions;

Expand Down Expand Up @@ -186,8 +187,23 @@ public static DebugProtocol.ExceptionInfoResponse ToExceptionInfoResponse(this E
FullTypeName = exception.Type,
Message = exception.Message,
InnerException = innerExceptions.Select(it => it.ToExceptionDetails()).ToList(),
StackTrace = string.Join('\n', exception.StackTrace?.Select(it => $" at {it?.DisplayText} in {it?.File}:line {it?.Line}") ?? Array.Empty<string>())
StackTrace = string.Join('\n', exception.StackTrace?.Select(it => it.ToStackTraceLine()) ?? Array.Empty<string>()),
};
}
private static string ToStackTraceLine(this ExceptionStackFrame? frame) {
var sb = new StringBuilder();
if (frame?.DisplayText == null)
return "<unknown>";

sb.Append(" ");
if (!frame.DisplayText.StartsWith("at "))
sb.Append("at ");

sb.Append(frame.DisplayText);
if (!string.IsNullOrEmpty(frame.File))
sb.Append($" in {frame.File}:line {frame.Line}");

return sb.ToString();
}
}

0 comments on commit 31e97ad

Please sign in to comment.