From 0a30e13bdcf87f4ac4949ba8dc90b34097f0c0d0 Mon Sep 17 00:00:00 2001 From: David Sarno Date: Fri, 3 Oct 2025 16:41:10 -0700 Subject: [PATCH] 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. --- UnityMcpBridge/Editor/Tools/ReadConsole.cs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/UnityMcpBridge/Editor/Tools/ReadConsole.cs b/UnityMcpBridge/Editor/Tools/ReadConsole.cs index 5bbf557b..f83e2cf3 100644 --- a/UnityMcpBridge/Editor/Tools/ReadConsole.cs +++ b/UnityMcpBridge/Editor/Tools/ReadConsole.cs @@ -303,14 +303,18 @@ bool includeStacktrace // --- Formatting --- string stackTrace = includeStacktrace ? ExtractStackTrace(message) : null; - // Get first line if stack is present and requested, otherwise use full message - string messageOnly = - (includeStacktrace && !string.IsNullOrEmpty(stackTrace)) - ? message.Split( - new[] { '\n', '\r' }, - StringSplitOptions.RemoveEmptyEntries - )[0] - : message; + // Always get first line for the message, use full message only if no stack trace exists + string[] messageLines = message.Split( + new[] { '\n', '\r' }, + StringSplitOptions.RemoveEmptyEntries + ); + string messageOnly = messageLines.Length > 0 ? messageLines[0] : message; + + // If not including stacktrace, ensure we only show the first line + if (!includeStacktrace) + { + stackTrace = null; + } object formattedEntry = null; switch (format)