From 890e7d0f0be91fc129da2356959fa67013a1c122 Mon Sep 17 00:00:00 2001 From: Hyungju Lee Date: Tue, 13 Sep 2022 14:15:29 +0900 Subject: [PATCH 1/2] Catch ArgumentOutOfRangeException dotnet-dump analyze causes an Exception when console top is -1 --- src/Microsoft.Diagnostics.Repl/ConsoleService.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Diagnostics.Repl/ConsoleService.cs b/src/Microsoft.Diagnostics.Repl/ConsoleService.cs index c14fba57b7..a6d53da353 100644 --- a/src/Microsoft.Diagnostics.Repl/ConsoleService.cs +++ b/src/Microsoft.Diagnostics.Repl/ConsoleService.cs @@ -246,6 +246,7 @@ private void CommandStarting() private void CommandFinished() { if (--m_commandExecuting == 0) { + m_activeLine = new StringBuilder(); RefreshLine(); } } @@ -268,7 +269,12 @@ private void ClearLine() Console.Write(m_clearLine); if (!m_outputRedirected) { - Console.CursorLeft = 0; + try { + Console.CursorLeft = 0; + } + catch (ArgumentOutOfRangeException) + { + } } } @@ -314,7 +320,12 @@ private void PrintActiveLine() Console.Write("{0}{1}", prompt, text); if (!m_outputRedirected) { - Console.CursorLeft = prompt.Length + (m_cursorPosition - m_scrollPosition); + try { + Console.CursorLeft = prompt.Length + (m_cursorPosition - m_scrollPosition); + } + catch (ArgumentOutOfRangeException) + { + } } } From a18a13bc325d943cbcbd22bb8812543e840dc2fe Mon Sep 17 00:00:00 2001 From: Hyungju Lee Date: Tue, 13 Sep 2022 19:50:37 +0900 Subject: [PATCH 2/2] Check CursorTop before changing CursorLeft --- .../ConsoleService.cs | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.Diagnostics.Repl/ConsoleService.cs b/src/Microsoft.Diagnostics.Repl/ConsoleService.cs index a6d53da353..bb139a000c 100644 --- a/src/Microsoft.Diagnostics.Repl/ConsoleService.cs +++ b/src/Microsoft.Diagnostics.Repl/ConsoleService.cs @@ -246,7 +246,6 @@ private void CommandStarting() private void CommandFinished() { if (--m_commandExecuting == 0) { - m_activeLine = new StringBuilder(); RefreshLine(); } } @@ -268,13 +267,8 @@ private void ClearLine() Console.Write(m_clearLine); - if (!m_outputRedirected) { - try { - Console.CursorLeft = 0; - } - catch (ArgumentOutOfRangeException) - { - } + if (!m_outputRedirected && Console.CursorTop >= 0 ) { + Console.CursorLeft = 0; } } @@ -319,13 +313,8 @@ private void PrintActiveLine() Console.Write("{0}{1}", prompt, text); - if (!m_outputRedirected) { - try { - Console.CursorLeft = prompt.Length + (m_cursorPosition - m_scrollPosition); - } - catch (ArgumentOutOfRangeException) - { - } + if (!m_outputRedirected && Console.CursorTop >= 0) { + Console.CursorLeft = prompt.Length + (m_cursorPosition - m_scrollPosition); } }