Improve stack trace error handling.

This commit is contained in:
Stone_Red
2026-03-04 23:38:01 +01:00
parent 882c4f3a51
commit 64c61f0f8c
@@ -123,13 +123,29 @@ internal sealed class RuntimeInformation
{ {
if (!Stop) if (!Stop)
{ {
Line line = Lines[Math.Min(LineNumber, Lines.Count - 1)]; if (Lines.Count == 0)
WriteLine($"{Environment.NewLine}[{(IsTask ? $"Task {TaskId}" : "The process")} was terminated at line {line.LineNumber + 1} in the file \"{line.FileName}\" with the message: {message}]", true); {
WriteLine($"{Environment.NewLine}[{(IsTask ? $"Task {TaskId}" : "The process")} was terminated with the message: {message}]", true);
}
else
{
Line line = Lines[Math.Min(LineNumber, Lines.Count - 1)];
WriteLine($"{Environment.NewLine}[{(IsTask ? $"Task {TaskId}" : "The process")} was terminated at line {line.LineNumber + 1} in the file \"{line.FileName}\" with the message: {message}]", true);
}
while (FunctionCallStack.Count > 0) while (FunctionCallStack.Count > 0)
{ {
int stackLineNumber = FunctionCallStack.Pop().CallerLine; int stackLineNumber = FunctionCallStack.Pop().CallerLine;
Line stackLine = (ParentRuntimeInformation?.Lines ?? Lines)[stackLineNumber]; List<Line> targetLines = ParentRuntimeInformation?.Lines ?? Lines;
WriteLine($" at line {stackLine.LineNumber + 1} in the file \"{stackLine.FileName}\"", true); if (stackLineNumber >= 0 && stackLineNumber < targetLines.Count)
{
Line stackLine = targetLines[stackLineNumber];
WriteLine($" at line {stackLine.LineNumber + 1} in the file \"{stackLine.FileName}\"", true);
}
else
{
WriteLine(" at unknown location (source not available)", true);
}
} }
Stop = true; Stop = true;