diff --git a/src/DotNet.Meteor.Debug/Extensions/ServerExtensions.cs b/src/DotNet.Meteor.Debug/Extensions/ServerExtensions.cs index b4b7eae..25eccc0 100644 --- a/src/DotNet.Meteor.Debug/Extensions/ServerExtensions.cs +++ b/src/DotNet.Meteor.Debug/Extensions/ServerExtensions.cs @@ -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; @@ -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()) + StackTrace = string.Join('\n', exception.StackTrace?.Select(it => it.ToStackTraceLine()) ?? Array.Empty()), }; } + private static string ToStackTraceLine(this ExceptionStackFrame? frame) { + var sb = new StringBuilder(); + if (frame?.DisplayText == null) + return ""; + + 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(); + } }