Skip to content

fix(invocation): #705 R7.1-R7.3 (errexit nounset rc, --, argument-less -o listing) - #778

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/705-invocation-diagnostics
Oct 17, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/705-invocation-diagnostics

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Fixes the three unambiguous items of #705 and reports the fourth (branding) as an open product-copy call. Every item was re-checked on current origin/master (7490feb0) against WSL GNU bash 5.3.0(1)-release (/usr/local/bin/bash), file-based.

Boundary note: the reporter invoked niu (the launcher), which reaches the engine through rubash::invocation::ShellInvocation and rubash::executor. This PR fixes the engine/lib surface; two of the user-visible symptoms also need the thin launcher's script-open path, called out below.

Per item

R7.1 -eu nounset exit status — reproduced, fixed

invocation GNU 5.3.0 master before this PR
bash -eu -c 'echo $UNDEF' 1 127 1
bash -u -c 'echo $UNDEF' 127 127 127
bash -u -c 'set -e; echo $UNDEF' 1 127 1
bash -eu -c 'set +e; echo $UNDEF' 127 127 127
bash -eu -c 'echo ${X?}' 1 127 1
bash -eu -c 'echo $((NOPE))' 1 127 1
bash -eu -c 'false || echo $UNDEF' 1 127 1
bash -eu script (echo $UNDEF) 1 1 1

Root cause, from the vendored C source: shell.c:1471 run_one_command only remaps the nounset FORCE_EOF jump to 127 with errexit off. With exit_immediately_on_error set (flags.c:263), error.c:169 report_error itself calls exit_shell(last_command_exit_value) — an EXITPROG jump with EXECUTION_FAILURE (1) — so the 127 remap is never reached. The predicate is the option value at the error site, so a ||/if context does not clear it (verified on the oracle). expansion_fatal_status now reads errexit_enabled() in the __RUBASH_IS_C arm. Diagnosis unchanged: bash: line 1: UNDEF: unbound variable.

R7.2 -- separator — partly reproduced, partly already fixed

invocation GNU 5.3.0 master engine this PR (lib)
printf 'echo X\n' | bash -- X, rc 0 X, rc 0 lib: read_stdin set
bash -- nosuch.sh rc 127, …: nosuch.sh: No such file or directory rc 127, same message unchanged
niu -- X, rc 0 bash: --: option requires a script, rc 2 read_stdin set
niu -- nosuch.sh rc 127, normal message niu: …️(os error 2), rc 1 see note
  • The left column is correct in the engine already; the niu launcher shares ShellInvocation, where -- with no operand was rejected. ShellInvocation::parse now ends option parsing on a lone -/-- (shell.c:905-911), takes the following word as the script and otherwise sets read_stdin (shell.c:780-786). This also fixes the lone - form, which previously fell through to the invalid-option arm.
  • Host follow-up (not this repo): niu -- nosuch.sh fails in the launcher's run_shell_invocation script branch, which does std::fs::read_to_string(...)? and surfaces the raw localized OS error with rc 1. The engine's own path already prints the normal …: nosuch.sh: No such file or directory + 127. The launcher should route ---introduced scripts through its existing missing-script handling (niu: <name>: No such file or directory, rc 127) instead of the ?.

R7.3 niu -o with no argument — reproduced, fixed (lib route)

invocation GNU 5.3.0 master engine master lib (niu route) this PR (lib)
bash -o name\tstate table, rc 0 table, rc 0 bash: -o: option requires an argument, rc 2 table, rc 0
bash +o set +o … recreate list, rc 0 list, rc 0 rc 2 list, rc 0
bash -o pipefail sets it sets it sets it sets it

shell.c:931-938 routes the argument-less -o/+o to list_minus_o_opts and keeps parsing; it is not a usage error. ShellInvocation now records the request (list_shell_options) and emits the table during option application, so a host that applies the invocation gets GNU's bytes with no host change; write_shell_options_listing exposes the exact output for tests. Flags parsed before the request are applied first, matching GNU's left-to-right walk.

Adjacent, unreported and left alone: -O/+O with no argument still errors in both the engine and the lib. bash -O prints the shopt table, rc 0.

R7.4 error-message branding — open, product-copy call

Current bytes, GNU vs the reporter's niu 1.4.0 vs this engine. Exit codes and streams otherwise match.

path GNU bash 5.3.0 niu 1.4.0 engine (rubash)
command not found bash: line 1: nosuchcmd: command not found niu: line 1: … bash: line 1: … (match)
syntax error bash: -c: line 2: syntax error: unexpected end of file from \if' command on line 1` niu: -c: line 2: … byte-identical to GNU
unbound variable bash: line 1: NOPE: unbound variable niu: line 1: … bash: line 1: … (match)
exit: too many args bash: line 1: exit: too many arguments rubash: exit: too many arguments rubash: exit: too many arguments
invalid long option bash: --bogus: invalid option bash: --bogus: invalid option match
invalid shell option bash: line 0: bash: bogusopt: invalid option name bash: line 0: bogusopt: invalid shell option name byte-identical to GNU

Two things are entangled and need an owner decision:

  1. The $0-vs-product prefix. GNU's error.c get_name_for_error derives the prefix from $0; a shell invoked as niu would print niu:. But the engine's compiled-in exit builtin hardcodes rubash: (src/builtins/exit.rs:64), and its other diagnostics print the canonical bash:. So the product currently mixes niu: / rubash: / bash: across paths. Should the engine's own diagnostics stay canonical bash: (script/test keying) or follow the invocation face?
  2. The line N: segment. GNU's exit: too many arguments carries line 1:; the engine's does not. That part is not branding and can be fixed independently once (1) is decided.

Per the ticket this is cosmetic; not changed here because it is a product-copy call. The niu-side rows are the launcher's and are out of this repo.

Tests

  • tests/issue705_nounset_errexit_status.rs — -eu/-u matrix (word, ${x?}, arithmetic, set -e/set +e, ||, script mode, subshell), exit statuses compared with WSL GNU bash 5.3.0; diagnostic bytes pinned.
  • tests/issue705_dashdash_separator.rs — parser contract for -/-- with and without an operand, plus engine routes (piped stdin, missing script → 127, script + positionals).
  • tests/issue705_option_list.rs — argument-less -o/+o parse and listing bytes (matches set -o/set +o), flags-before-list ordering, named form unchanged, engine -o/+o routes.

All three sandbox the CWD under the system temp dir. cargo fmt --check clean; cargo test --lib 689 passed; the existing invocation/errexit/nounset suites (issue585/590/591/626, issue154/307/311/319/358/529/535/547/637/638/639, cli_tests errexit::*) pass.

R7.1: the fatal word-expansion error (`set -u` word, `${var?}`, nounset arithmetic) exits 127 at the `-c` top level because shell.c:1471 run_one_command remaps the FORCE_EOF jump. GNU only reaches that remap with errexit OFF: error.c:169 report_error, when exit_immediately_on_error is set (flags.c:263), calls exit_shell(last_command_exit_value) — an EXITPROG jump with EXECUTION_FAILURE (1). So `bash -eu -c 'echo $UNDEF'` exits 1 while `bash -u -c 'echo $UNDEF'` exits 127, and the option value at the error site decides (an `if`/`||` context does not clear it).

expansion_fatal_status now reads errexit_enabled() in the __RUBASH_IS_C arm.

Tests: tests/issue705_nounset_errexit_status.rs compares the `-eu`/`-u` matrix byte-for-byte with WSL GNU bash 5.3.0.
…ng (#705)

R7.2: GNU shell.c:905-911 ends option parsing on a lone `-` or `--`; the next word is the script and, with none, the shell reads stdin (shell.c:780-786). ShellInvocation::parse rejected `--` with no operand (`--: option requires a script`) and a lone `-` fell to the invalid-option arm, so the niu host errored where `bash --` reads stdin.

R7.3: shell.c:931-938 treats `-o`/`+o` with no following word as the LIST form (list_minus_o_opts), prints the table and continues — not a usage error. The parser now records the request so the table renders during option application (the engine binary already listed through its own parser, rubash#547); `-o <name>` is unchanged. write_shell_options_listing exposes the exact bytes for hosts and tests.

Tests: tests/issue705_dashdash_separator.rs and tests/issue705_option_list.rs pin the parser contract and the engine routes; the `-o` table bytes match WSL GNU bash 5.3.0.
@caomengxuan666
caomengxuan666 merged commit c4ca8eb into master Oct 17, 2026
8 checks passed
caomengxuan666 added a commit that referenced this pull request Oct 17, 2026
…redicate (#738 #780 #727)

Three open-issue fixes from the 2026-10-17 sweep.

#738 heredoc delimiter was dequoted by DELETING the quote characters:
`<<E\'OF` named `EOF`, the terminator `E'OF` never matched, and the
heredoc ran to end-of-file — silently consuming the rest of the script
with rc 0 and a warning most scripts never read. Four sites did
`replace(['\'','"','\\'], "")`. New
`lexer::heredoc_scan::dequote_heredoc_delimiter` implements GNU
`string_quote_removal` (an escaped character stays literal, a quoted run
keeps its bytes, double-quote backslash rules); skip.rs / heredoc_scan.rs
/ execution_misc.rs / alias_stream.rs all route through it. The word
token also carries an escaped quote/backslash as DATA_SQUOTE /
DATA_BACKSLASH, so `heredoc_delimiters` decodes those carriers before
comparing body lines.

#780 argument-less `-O`/`+O`: GNU shell.c routes it to the shopt table
(`-O` = the `shopt` bytes, `+O` = the `shopt -p` bytes), rc 0 — the
sibling of the `-o`/`+o` case fixed in #547/#778. ShellInvocation gains
`list_shopt_options` + `write_shopt_options_listing`, and both the engine
parser and `parse_post_c_option` take the list form instead of a usage
error.

#727 the golden marker-leak assertion scanned lead byte 0xEF:
U+E000..=U+EFFF is 0xEE (0xEF starts U+F000). It therefore could not see
any registered marker and only ever fired on user data. Fixed, plus two
self-tests (a registered marker must be caught; U+F000 must not).
With the predicate finally live, `xtrace_carries_no_markers` had to stop
asserting "no PUA" on output that IS user PUA — it now asserts the
literal round-trip (one char per traced word, no E400 escape, no named
marker).

Tests (all four run in the windows-latest regression job):
  heredoc_delimiter_with_escaped_quote_or_backslash_terminates
  argument_less_capital_o_prints_the_shopt_listing
  marker_leak_golden::pua_assertion_sees_a_registered_marker
  marker_leak_golden::pua_assertion_ignores_the_f000_block
Lib 609 passed. Regression: the three failures this tree shows
(golden_fnbody_strict_battery's stale `array-y` golden, and the two
yes|head SIGPIPE canaries) reproduce identically on the pristine parent.
@caomengxuan666
caomengxuan666 deleted the fix/705-invocation-diagnostics branch October 18, 2026 09:29
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.

1 participant