Skip to content

Commit 0a30e13

Browse files
committed
Fix read_console includeStacktrace parameter behavior
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 47ec46c commit 0a30e13

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
@@ -303,14 +303,18 @@ bool includeStacktrace
303303

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

315319
object formattedEntry = null;
316320
switch (format)

0 commit comments

Comments
 (0)