Skip to content

fix(interpreter): arithmetic errors report and fail instead of giving 0 - #2604

Merged
chaliy merged 2 commits into
mainfrom
claude/arith-errors
Oct 7, 2026
Merged

chaliy merged 2 commits into
mainfrom
claude/arith-errors

Conversation

@chaliy

@chaliy chaliy commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

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

What changed

Arithmetic evaluation now has an error channel instead of silently producing 0.

  • $((1/0)), $((1%0)), $((08)) and $((2#12)) print bash's message and abort the command with status 1.
  • (( )) and let print the same message with their own ((: / let: prefix, fail with status 1, and let the script continue, as bash does.
  • Valid literals are unchanged: 0x1f, 010, 16#ff, 10#08, 2#101, 64#@.

Why

A script computing $((total/count)) with count=0 got 0 and carried on with a wrong number and a zero exit status. Debian-oracle cases arith-errors and integer-overflow-and-base.

Before / After

Script Before After (matches bash)
echo $((1/0)); echo after 0, then after, status 0 bash: line 1: 1/0: division by 0 (error token is "0"), status 1, after not run
echo $((08)) 0 bash: line 1: 08: value too great for base (error token is "08")
((1/0)); echo $? 1 with no message bash: line 1: ((: 1/0: division by 0 ... then 1
let "y=1/0"; echo $? 1 with no message bash: line 1: let: y=1/0: division by 0 ... then 1

New spec file arith-errors.test.sh (4 cases), verified against bash 5.2.

Risk

Medium-low. Scripts that relied on a silent 0 from a division by zero now fail, which is the point. The error carries over &self in a Mutex<ArithError> on the interpreter (it must stay Sync), locked only on the arithmetic path. An empty right operand, which the operator scan can produce inside a signed literal like -9223372036854775808 / -1, is not treated as a zero divisor, so those paths keep their old values. Error lines read bash: line N: rather than naming the script, since the interpreter does not track the running script's path.

Checklist

  • Failing spec first, verified against real bash
  • cargo test -p bashkit --lib, --test integration, bash_comparison
  • cargo clippy --all-targets -D warnings, cargo fmt --check
  • Recursion stack probe: 2020 KB (main 2028-2036 KB)
  • knowledge/log.md updated

https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA


Generated by Claude Code

@chaliy chaliy self-assigned this Oct 7, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 7, 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 a32e2de Commit Preview URL

Branch Preview URL
Oct 07 2026, 11:23 PM

@chaliy
chaliy force-pushed the claude/arith-errors branch 2 times, most recently from b1b7714 to 8f2ebed Compare October 7, 2026 22:59
chaliy added 2 commits October 7, 2026 23:22
Division by zero and a literal outside its base now print bash's message and
exit 1; (( )) and let report it themselves and keep the script running.

Claude-Session: https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA
The Python and JS security suites asserted bashkit printed 0 for
division and modulo by zero. It now reports like bash and fails, so
the expectations move with it.

Claude-Session: https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA
@chaliy
chaliy force-pushed the claude/arith-errors branch from 8f2ebed to a32e2de Compare October 7, 2026 23:22
@chaliy
chaliy merged commit 5572021 into main Oct 7, 2026
44 checks passed
@chaliy
chaliy deleted the claude/arith-errors branch October 7, 2026 23:50
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