fix(rails): unknown command should exit 1 and write to stderr#25
Open
crossi-dev wants to merge 1 commit into
Open
fix(rails): unknown command should exit 1 and write to stderr#25crossi-dev wants to merge 1 commit into
crossi-dev wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #10
Problem
An unknown command always exits
0. Ingem/terminalwire-rails/lib/terminalwire/rails.rb, the rescue forThor::UndefinedCommandError/Thor::InvocationErrorwrites the message to stdout and never sets the exit code, so theensureblock always callscontext.exit 0. Scripts and CI can't detect the failure.Fix
Treat it like the
StandardErrorhandler right below it — error to stderr, exit code1:Two-line change; mirrors the existing error-handling pattern in the same method.
Verified
Standalone repro of the rescue/ensure path (Ruby 3.3):
stderr routing + non-zero exit confirmed; normal commands unaffected.
Came across Terminalwire and noticed #10 had been open a while, so I went ahead and fixed it. No strings attached — I'm with Choreless and we like contributing real fixes to projects we use. If it's useful and you ever want a hand with something larger, happy to help.
— Charles