fix: propagate exit code from REPL to process exit status#51
Merged
Conversation
Shell::run() now returns anyhow::Result<ExitCode> instead of Result<()>. main() calls std::process::exit() with the returned code so that exit 0 and exit 1 are reflected in the ferrish process exit status. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Updates ferrish’s control flow so the REPL’s exit <code> value becomes the actual process exit status, and extends the integration-test harness to assert on exit codes.
Changes:
- Change
Shell::run()andferrish::run()to returnExitCodeinstead of(). - Update
main()to exit the process with the returnedExitCode. - Extend the test harness (
TestResult) and add REPL tests that assert exit-code propagation.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/shell.rs |
Propagates ExitCode out of the interactive REPL loop. |
src/lib.rs |
Updates public run() API to return ExitCode. |
src/main.rs |
Exits the process using the propagated exit code. |
tests/harness.rs |
Captures ExitCode in TestResult for assertions. |
tests/repl.rs |
Adds integration tests verifying exit N propagates correctly. |
- main() returns anyhow::Result<std::process::ExitCode>; ? propagates fatal errors with full anyhow context, and the Termination impl exits the process with the shell's actual exit code - Add From<ExitCode> for std::process::ExitCode to exit.rs; avoids accessing the inner field directly from main - Remove stale TODO from run_script(); exit code is already returned - Restore #[allow(dead_code)] on exit_code field and method; harness.rs compiles into multiple test binaries, only repl.rs uses exit_code() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
BufRead::read_until returns 0 bytes at EOF; continuing the loop caused the REPL to repeatedly print the prompt when stdin was closed (Ctrl-D or piped input exhausted). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
Shell::run()return type changed fromanyhow::Result<()>toanyhow::Result<ExitCode>lib::run()propagates the new return typemain()returnsanyhow::Result<std::process::ExitCode>; the?operator propagates fatal errors with full anyhow context, and theTerminationimpl exits the process with the shell's actual exit codeFrom<ExitCode> for std::process::ExitCodeinexit.rsto keepmaincleanrun()now returnsOk(ExitCode::SUCCESS)on a 0-byte read instead of spinning the REPL loopTest plan
test_exit_zero_propagates—exit 0returnsExitCode(0)test_exit_nonzero_propagates—exit 1returnsExitCode(1)test_exit_arbitrary_code_propagates—exit 42returnsExitCode(42)TestResultin the harness now exposesexit_code()for future tests🤖 Generated with Claude Code