fix(console): restore pump error logging; drop unused Stop; stop invalidating help cache on lookup

- ConsoleInputPump gains an optional ILogger so the reader-fault and
  command-dispatch catch blocks log warnings/errors again, matching the
  behavior the old ConsoleInputHandler had before the pump refactor.
- Remove ConsoleInputPump.Stop() — dead code, nothing calls it; the reader
  thread already terminates on EOF/Core.Closing/finally cleanup.
- GetInputCommand no longer clears the help-description cache on every
  lookup; RegisterCommand/UnregisterInputCommand still invalidate it
  correctly on the paths that actually change the command set.
This commit is contained in:
Kamron Batman 2026-07-15 22:18:15 -07:00
parent 45ea449419
commit 9cced198f9
2 changed files with 8 additions and 11 deletions

View file

@ -69,7 +69,6 @@ public static class ConsoleInputHandler
lock (_inputCommands)
{
var action = _inputCommands.GetValueOrDefault(command)?.Function;
_commandDescriptions = null;
return action;
}
}
@ -88,7 +87,7 @@ public static class ConsoleInputHandler
return;
}
_pump = new ConsoleInputPump(Console.In, GetInputCommand);
_pump = new ConsoleInputPump(Console.In, GetInputCommand, logger);
new Thread(_pump.Run)
{

View file

@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Threading;
using Server.Logging;
namespace Server;
@ -17,6 +18,7 @@ internal sealed class ConsoleInputPump
{
private readonly TextReader _input;
private readonly Func<string, Action<string>> _lookup;
private readonly Server.Logging.ILogger _logger;
private readonly object _gate = new();
private readonly AutoResetEvent _promptDelivered = new(false);
@ -24,20 +26,15 @@ internal sealed class ConsoleInputPump
private string _promptResult;
private volatile bool _running = true;
public ConsoleInputPump(TextReader input, Func<string, Action<string>> lookup)
public ConsoleInputPump(TextReader input, Func<string, Action<string>> lookup, Server.Logging.ILogger logger = null)
{
_input = input ?? throw new ArgumentNullException(nameof(input));
_lookup = lookup ?? throw new ArgumentNullException(nameof(lookup));
_logger = logger;
}
public bool Running => _running;
public void Stop()
{
_running = false;
ReleasePendingPrompt(null);
}
public void Run()
{
try
@ -51,6 +48,7 @@ internal sealed class ConsoleInputPump
}
catch
{
_logger?.Warning("Console commands have been disabled due to an error.");
break;
}
@ -93,9 +91,9 @@ internal sealed class ConsoleInputPump
var action = _lookup(split[0].ToLower());
action?.Invoke(split.Length > 1 ? split[1] : string.Empty);
}
catch
catch (Exception e)
{
// A throwing lookup or handler logs its own failures; never let one kill the loop.
_logger?.Error(e, "Failed to execute console command: {Command}", line);
}
}
}