Repository navigation
fix(repl): end the session on top-level exit jumps (command lists, aliases, functions) - #544
Merged
Catapult291 merged 1 commit intoOct 24, 2026
Conversation
…efects 2026-10-24) D1 made a whole-line `exit N` end the REPL, but a top-level exit inside a command list, alias, or function body only unwound the engine: the grouped reader route (every `;`/`&&`/alias-bearing line) computed the exit-shell verdict and discarded it, and the tokenize+parse route swallowed ExecuteError::ExitCode into a plain status — so `true; exit 3` printed and the REPL kept prompting (R1, niubash-remaining-defects 2026-10-24). - execute_interactive_reader_batch takes the new tracked grouped verdict (rubash run_script_with_history_at_line_offset_tracked) and records it. - execute_line_with_options and execute_script_inner record a session jump for ExitCode/FatalFunctionError; take_parse_error() screens out the parse abort, so an interactive syntax error still discards only its own group and keeps prompting (eval.c:202-205). - execute_host_synced_simple_ast propagates ExitCode instead of flattening it to Ok(code), so `cd X; exit N` shapes record the jump on both the interactive and script routes (the script side is what niubash#402 wanted all along). - The line-editor loop, the --noediting loop, and the widget-submit path take the jump right after each submission and end the session through end_repl_session (EXIT trap, history flush, host exit status). Taken into a `let` first: an if-let scrutinee would hold its borrow_mut() temporary through the body and panic on the second RefCell borrow (observed as fail-fast rc 0xC0000409 before the fix). - execute_interactive_line/script drop a stale jump recorded outside the submission (mid-session rc re-source, niubash#180). Verified: 4 new unit tests + full niubash-runtime suite (582+ lib, 0 failed); ConPTY probe (pywinpty) on both the built and installed niu.exe: exit 3 / exit / logout 3 / exit 5; keep rc, `true; exit 3`=3, `false; exit 5`=5, `echo hi; exit 7`=7, function=4, alias bye 3=3 all end the session with the right status, while `(exit 3)`, `echo exit`, `exit abc`, `exit 3 4`, `exit --help` stay alive; `niu -c` exit codes unchanged; D4 streaming probe unchanged (cat first line 0.034s).
Catapult291
force-pushed
the
fix/interactive-exit-jump-bubble
branch
from
October 24, 2026 02:05
2548c15 to
e04721c
Compare
caomengxuan666
added a commit
that referenced
this pull request
Oct 24, 2026
… rustfmt) Master's fmt gate is red since #544 on the current stable toolchain; CI's rustfmt wants this call wrapped. Mechanical normalization so the PR's merge preview passes cargo fmt --check. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.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
After #541, a line that was exactly
exit Nends the REPL, but a top-level exit inside a compound/alias/function form only unwound the engine and kept prompting:true; exit 3false; exit 5alias bye=exit+bye 3f(){ exit 4; }+f(exit 3)echo exit/exit abc/exit --helpRoot cause: the grouped-reader route (every
;/&&/alias line) computed the exit-shell verdict and dropped it; the tokenize+parse route swallowedExecuteError::ExitCodeinto a plain status. The script path (niu -c 'true; exit 3'→ rc=3) was already correct.Changes
Shell::session_exit_jump: Option<i32>+take_session_exit_jump(); entry points clear stale values so a leftover jump cannot kill the next line.execute_interactive_reader_batchconsumes the new rubash tracked grouped verdict (run_script_with_history_at_line_offset_tracked) and records the jump.execute_line_with_options/execute_script_innerrecord a jump onExitCode/FatalFunctionError;take_parse_error()screens out parse aborts so an interactive syntax error only drops its own group and keeps prompting (eval.c:202-205).execute_host_synced_simple_astpropagatesExitCodeinstead of flattening it toOk(code), socd X; exit Nrecords the jump on both the interactive and script routes (the script side is what niubash#402 wanted).--noeditingloop, and the widget-submit pathtakethe jump after each submission and end via the existingend_repl_session(EXIT trap → history flush →process::exit(code)).Companion engine PR (must land together): unixwin/rubash#1453 (
fix/grouped-reader-exit-jump-verdict) — tracked grouped verdict +exit --helpGNU continue (without it,exit --helpwould kill the session once jumps bubble).Test plan
cargo test -p niubash-runtime: 586 + 10 + 8 + 3 passed, 0 failed (includes 4 new jump unit tests).niu -c 'true; exit 3'/-c 'exit 3'/-c 'echo hi; exit 7'→ 3/3/7;-c 'exit --help; echo AFTER'prints AFTER rc=0; D4 streaming| catstill first-line ~0.03s.Follow-up to niubash defect log R1 (
niubash-remaining-defects-2026-10-24). cherry-picked from localf8d4206, rebased onto master after #542 landed: the interactiveExitCodearms keep #542'sset_last_exit_codeso$?matches 130 after Ctrl-C, and additionally callnote_session_exit_jumpso the session ends.