Skip to content

fix(interpreter): a failed arithmetic expansion does not truncate the script - #2616

Closed
chaliy wants to merge 1 commit into
mainfrom
claude/arith-error-continues
Closed

chaliy wants to merge 1 commit into
mainfrom
claude/arith-error-continues

Conversation

@chaliy

@chaliy chaliy commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Requested by Михайло · project thread

What changed

A failed $(( )) now fails its own command and nothing more. It still ends an
enclosing subshell, which is what bash does, but it no longer stops the script.

Why

Follow-up to #2604. Reporting arithmetic errors reused the abort path set -u
needs, so the first division by zero silently truncated the run — the error was
printed and everything after it was skipped, with the script exiting 0.

Before / After

echo before
echo $((1/0))
echo "rc=$?"
echo after
output status
bash 5.2 before, the error, rc=1, after 0
bashkit before before, the error — nothing else ran 0
bashkit after same as bash 0

A subshell still stops, as in bash:

( echo before; echo $((1/0)); echo never ); echo "rc=$?"

gives before and rc=1 in both shells — never does not run.

Risk

Low. The failure carries ControlFlow::Return(1) exactly as before, so every
subshell, function and $( ) boundary behaves as it did; one flag tells the
outermost script loop that this particular Return(1) came from arithmetic and
is not a reason to stop. set -u still ends the script.

Checklist

  • cargo test -p bashkit --lib (2920 passed)
  • cargo test -p bashkit --test integration (1368 passed)
  • New spec case for the script-continues path, verified against bash 5.2
  • bash_comparison differential tests against real bash
  • cargo clippy -p bashkit --all-targets -- -D warnings
  • cargo fmt --all --check
  • cargo test -p bashkit-cli (56 passed)
  • just check-okf
  • Stack probe: 1900 KB, inside the two-MiB TM-DOS-020 budget
  • Knowledge updated (log.md)

https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA


Generated by Claude Code

… script

`echo $((1/0))` reported the error and then stopped the script: the
failure reused the abort path `set -u` needs. It now ends only the
enclosing subshell, as bash does, so the command fails with status 1 and
the next one runs.

Claude-Session: https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA
@chaliy chaliy self-assigned this Oct 8, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit c03e4b9 Commit Preview URL

Branch Preview URL
Oct 08 2026, 12:26 AM

chaliy commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded: main now handles arithmetic failures through the line-abort path (#2604 and follow-ups), and this PR's new spec case (echo $((1/0)) then rc=1, script continues) passes on main unchanged. Subshell, brace group, function and if bodies also match bash 5.2 on main.


Generated by Claude Code

@chaliy chaliy closed this Oct 8, 2026
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