From a3dd5b516648e3ec2dd5b70de3524589d43f158c Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 31 May 2024 09:43:41 +1000 Subject: [PATCH] Attempt to catch UnauthorizedAccessException when reading from stdin to avoid constant error log spam when stdin is unreadable This can happen e.g. if being run in nohup mode --- CLI/Program.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CLI/Program.cs b/CLI/Program.cs index 6a28c14fb..c08456bae 100644 --- a/CLI/Program.cs +++ b/CLI/Program.cs @@ -199,6 +199,12 @@ static void ConsoleLoop() { } else { UIHelpers.HandleChat(msg); } + } catch (UnauthorizedAccessException) { + // UnauthorizedAccessException can get thrown when stdin is unreadable + // See https://github.com/dotnet/runtime/issues/21913 for instance + Write("&e** Access denied to stdin, console no longer accepts input **"); + Write("&e** If nohup is being used, remove that to avoid this issue **"); + break; } catch (Exception ex) { // ArgumentException is raised on Mono when you: // 1) Type a message into a large CLI window