Skip to content

errexit/trap: set -e misfires in until ... break|continue; set -E not inherited by ( ) subshells #702

Closed

Description

@caomengxuan666

Summary

Two errexit / trap-inheritance divergences from GNU bash, both deterministic.

Environment: Niubash 1.4.0 · rubash git e785c3c8f610 — Windows 10 x64.
Method: differential vs GNU bash 5.2.21(1) / 5.3.0.


R4.1 set -e misfires in an until loop whose body starts with break / continue

$ set -e; until false; do break; done; echo REACHED
niu : exits 1, REACHED not printed
bash: REACHED   (rc 0)

Characterization (all re-checked on both shells):

  • Only until is affected. while true; do break; done and for i in 1; do break; done are fine.
  • Trigger: the first command executed in the body is break or continue (or a group starting with one: until false; do { break; }; done). If any other command precedes it (until false; do :; break; done) it is fine.
  • The status applied is the loop condition's: set -e; until (exit 7); do break; done exits 7.
  • It also fires the ERR trap with the condition's status: set -e; trap 'echo ERR:$?' ERR; until false; do break; done → niu prints ERR:1; bash runs the body and continues.
  • Without set -e both shells report $? = 0 after the loop — the loop's own status is correct; the stray status only leaks into the errexit / ERR-trap check.

The continue form aborts a loop that would terminate normally:

$ set -e; i=0; until [ $((++i)) -ge 2 ]; do continue; done; echo REACHED
niu : exits 1, no output     bash: REACHED

R4.2 set -E (errtrace) is not inherited by ( ) subshells

$ set -E; trap 'echo ERR' ERR; ( false ); echo done
niu : ERR / done            (1 ERR)
bash: ERR / ERR / done      (2 ERR — the inherited trap fires for `false` inside the subshell, then again for the failing subshell command)

Stable across 5 consecutive runs. set -E is accepted (shopt -o -p errtrace → set -o errtrace), and function inheritance works: set -E; trap 'echo ERR' ERR; f(){ false; }; f → 2 ERR on both. The gap is specifically the subshell fork copy path: ( f ) with -E → GNU 3 ERR vs niu 1.

Also visible through command substitution: o=$(set -E; trap 'echo E' ERR; (false)) embeds two E on GNU, one on niu.

Activity

  1. added
    bug
    P1-high
    on Oct 17, 2026
  2. caomengxuan666 commented on Oct 17, 2026

    @caomengxuan666
    MemberAuthor

    Version note (correction to the Method line): the oracle was reached with bare wsl.exe -e bash, which resolves through PATH to /usr/local/bin/bash = GNU bash 5.3.0(1) — not 5.2.21. The 5.2.21 build lives at /bin/bash, and every item in this report was re-checked on it as well; results were identical on both.

    So the two versions are listed in the wrong order above: 5.3.0 was the default, 5.2.21 the cross-check.

    No finding here changes; noting it only so the numbers reproduce. (Incidentally 5.3.0 is also the oracle cited in rubash#641, "the repository oracle is WSL 5.3.0".)

  3. added
    family:S8
    family:S9
    on Oct 17, 2026
  4. caomengxuan666 commented on Oct 17, 2026

    @caomengxuan666
    MemberAuthor

    Verified fixed on master — closing

    Re-measured with the regression catalogue harness (WSL GNU bash 5.3.0 as oracle; both arms bounded; stdout/stderr/rc captured separately; the arm must reach the end of the script):

    arm result
    installed 1.4.0 (rubash e785c3c8f610) set -e; until false; do break; done; echo REACHED1 → no output at all, rc 1 — the shell died at the until, exactly as filed
    master (engine 30aaf207, 2026-10-17) REACHED1 / REACHED2, rc 0 — matches GNU byte-for-byte

    Both statements from the issue (the break form and the continue form with [ $((++i)) -ge 2 ]) are covered by the case and both now match, and the tree carries tests/issue702_errexit_until_break_regressions.rs.

    Thanks — closing as fixed. (Kept as resolved rather than a duplicate, since the fix postdates the build I originally measured on.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1-highbugfamily:S8family:S9

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions