Skip to content

[bug] Function-local ERR trap never fires (only checks final status) #1163

Closed

Description

@caomengxuan666

[bug] Function-local ERR trap never fires unless the failing command is the function's last and the function ends non-zero — HIGH

f() { trap 'echo ERRTRAP' ERR; false; echo hello; }
f
echo outer-rc=$?
# GNU bash 5.3:  ERRTRAP / hello / outer-rc=0
# niu:           hello / outer-rc=0 (no fire)

Variants: false; true, $?-read after, two failures → bash fires twice / niu zero times, subshell failure inside function, bare-return action (bash E|outer-rc=1, niu inner|outer-rc=0), exit-action (bash exits 42, niu prints never|after-0). niu behaves as if it checks only the function's final status at exit instead of firing per failing command. Silent trap loss.

Env: niubash 1.4.4 / rubash engine (master ~2026-10), GNU bash 5.3.20 aarch64-linux-android as oracle.

Activity

  1. added
    bug
    gnu-baseline
    area:jobs
    family:S9
    P1-high
    on Oct 22, 2026
  2. caomengxuan666 commented on Oct 23, 2026

    @caomengxuan666
    MemberAuthor

    Triage vs current master (e743db8, release build): no longer reproduces — function-local ERR trap now fires per failing command.

    $ f(){ trap "echo ERRTRAP" ERR; false; echo hello; }; f; echo outer-rc=$?
    GNU 5.3.20:  ERRTRAP / hello / outer-rc=0
    rubash:      ERRTRAP / hello / outer-rc=0
    

    Fixed by #1181. Closing.

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-higharea:jobsbugfamily:S9gnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions