Skip to content

Commit ff73601

Browse files
authored
Fix read_console includeStacktrace parameter behavior (#304)
The includeStacktrace parameter was working backwards - when false, it would return the full message with embedded stack traces, and when true, it would extract the stack trace but the logic was inverted. Changes: - Always extract the first line as the message text - Only populate stackTrace field when includeStacktrace is true - Ensures clean, summary-only messages when includeStacktrace is false - Properly separates stack traces into their own field when requested This matches the expected Unity console behavior where the summary is shown by default, and stack traces are only shown when expanded.
1 parent 5488af2 commit ff73601

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

UnityMcpBridge/Editor/Tools/ReadConsole.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,18 @@ bool includeStacktrace
304304

305305
// --- Formatting ---
306306
string stackTrace = includeStacktrace ? ExtractStackTrace(message) : null;
307-
// Get first line if stack is present and requested, otherwise use full message
308-
string messageOnly =
309-
(includeStacktrace && !string.IsNullOrEmpty(stackTrace))
310-
? message.Split(
311-
new[] { '\n', '\r' },
312-
StringSplitOptions.RemoveEmptyEntries
313-
)[0]
314-
: message;
307+
// Always get first line for the message, use full message only if no stack trace exists
308+
string[] messageLines = message.Split(
309+
new[] { '\n', '\r' },
310+
StringSplitOptions.RemoveEmptyEntries
311+
);
312+
string messageOnly = messageLines.Length > 0 ? messageLines[0] : message;
313+
314+
// If not including stacktrace, ensure we only show the first line
315+
if (!includeStacktrace)
316+
{
317+
stackTrace = null;
318+
}
315319

316320
object formattedEntry = null;
317321
switch (format)

0 commit comments

Comments
 (0)