From 384b4687d362205f019b50e9a4c5950d62cf7660 Mon Sep 17 00:00:00 2001 From: Charles Rossi Date: Mon, 15 Jun 2026 03:10:11 -0300 Subject: [PATCH] fix(rails): write unknown command error to stderr and exit 1 When Thor raises UndefinedCommandError or InvocationError, the error message was written to stdout and the process exited with code 0, making it impossible for callers to detect the failure. Write the error to stderr (consistent with the StandardError handler) and set exit_code to 1 so the ensure block propagates the failure to the client via context.exit. --- gem/terminalwire-rails/lib/terminalwire/rails.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gem/terminalwire-rails/lib/terminalwire/rails.rb b/gem/terminalwire-rails/lib/terminalwire/rails.rb index eba799a..82e52c1 100644 --- a/gem/terminalwire-rails/lib/terminalwire/rails.rb +++ b/gem/terminalwire-rails/lib/terminalwire/rails.rb @@ -172,7 +172,8 @@ def handle(adapter:, env:) cli.default_url_options[:host] = env["HTTP_HOST"] end rescue ::Thor::UndefinedCommandError, ::Thor::InvocationError => e - context.stdout.puts e.message + context.stderr.puts e.message + exit_code = 1 rescue ::StandardError => e # Log the error handler_error_message = <<~ERROR