Skip to content

Reraise a runtime arithmetic error as Expression.Error - #372

Merged
joaothallis merged 1 commit into
developfrom
reraise-arithmetic-error-as-expression-error
Sep 17, 2026
Merged

joaothallis merged 1 commit into
developfrom
reraise-arithmetic-error-as-expression-error

Conversation

@joaothallis

@joaothallis joaothallis commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Why

evaluate_block!/4 and evaluate!/4 already convert a RuntimeError raised during evaluation into an Expression.Error. That is how a non-numeric operand surfaces: the numeric guard does raise "expression is not a number" (a RuntimeError), which the rescue reraises as Expression.Error, so callers get a typed evaluation error instead of a crash.

A division by zero is the one arithmetic failure that slips through. The operands are valid numbers, so the guard passes, and the raw Kernel.//2 then raises ArithmeticError, which is not a RuntimeError. It escaped the rescue and crashed the calling process.

What

Add ArithmeticError alongside RuntimeError in both reraise clauses, so any runtime arithmetic fault surfaces as an Expression.Error (type: :eval), consistent with every other unusable value.

evaluate_as_string!/4 is intentionally left as is: it does not wrap RuntimeError either, so an ArithmeticError-only rescue there would be inconsistent.

🤖 Generated with Claude Code

`evaluate_block!/4` and `evaluate!/4` already convert a `RuntimeError` raised
during evaluation into an `Expression.Error`; this is how a non-numeric operand,
which raises "expression is not a number", surfaces to callers. A division by
zero is the one arithmetic failure that slips through: the operands are valid
numbers, so the numeric guard passes, and the raw `Kernel.//2` then raises
`ArithmeticError`, which is not a `RuntimeError` and so escaped the rescue and
crashed the caller.

Add `ArithmeticError` alongside `RuntimeError` in both reraise clauses so any
runtime arithmetic fault surfaces as an `Expression.Error`, consistent with every
other unusable value.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@joaothallis
joaothallis force-pushed the reraise-arithmetic-error-as-expression-error branch from 3bc17a7 to ffaef8a Compare September 17, 2026 02:15
@joaothallis
joaothallis merged commit 3dbfffb into develop Sep 17, 2026
2 checks passed
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.

2 participants