Skip to content

fix: propagate exit code from REPL to process exit status#51

Merged
cdprice02 merged 3 commits intomainfrom
fix/propagate-exit-code
Apr 7, 2026
Merged

fix: propagate exit code from REPL to process exit status#51
cdprice02 merged 3 commits intomainfrom
fix/propagate-exit-code

Conversation

@cdprice02
Copy link
Copy Markdown
Owner

@cdprice02 cdprice02 commented Apr 6, 2026

Summary

  • Shell::run() return type changed from anyhow::Result<()> to anyhow::Result<ExitCode>
  • lib::run() propagates the new return type
  • main() returns anyhow::Result<std::process::ExitCode>; the ? operator propagates fatal errors with full anyhow context, and the Termination impl exits the process with the shell's actual exit code
  • Added From<ExitCode> for std::process::ExitCode in exit.rs to keep main clean
  • Fixed stdin EOF handling: run() now returns Ok(ExitCode::SUCCESS) on a 0-byte read instead of spinning the REPL loop
  • Resolves Propagate exit code from REPL to process exit status #16

Test plan

  • test_exit_zero_propagatesexit 0 returns ExitCode(0)
  • test_exit_nonzero_propagatesexit 1 returns ExitCode(1)
  • test_exit_arbitrary_code_propagatesexit 42 returns ExitCode(42)
  • TestResult in the harness now exposes exit_code() for future tests
  • All existing tests pass

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings April 6, 2026 23:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() and ferrish::run() to return ExitCode instead of ().
  • Update main() to exit the process with the returned ExitCode.
  • 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>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

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>
@cdprice02 cdprice02 merged commit 51c1642 into main Apr 7, 2026
8 checks passed
@cdprice02 cdprice02 deleted the fix/propagate-exit-code branch April 7, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Propagate exit code from REPL to process exit status

2 participants