fix(error): stdlib bad-arg raises auto-populate line and source#215
Merged
Conversation
A18 wired line/source through every executor raise and through the
assert/error native-call boundary. This finishes the job for every
other stdlib raise (string.upper(nil), math.floor("x"), table.insert
with bad pos, etc.) by having the four exception modules — RuntimeError,
TypeError, AssertionError, ArgumentError — auto-populate :line / :source
from Executor.current_position/0 inside exception/1 when not given.
Zero callsite changes for ~80 ArgumentError raises across math, string,
table, and the rest of stdlib. Explicit opts still win (raise sites that
already pass :line / :source — like the executor's safe_* helpers and
the divide-by-zero / modulo-by-zero sites — are unaffected).
ArgumentError gains :line, :source, :call_stack fields and now renders
through Lua.VM.ErrorFormatter so the "at <source>:<line>:" prefix shows
up consistently with the other exceptions.
Verified:
- 1577 -> 1585 tests pass (+8 new in error_messages_test).
- 5/29 lua53 suite still passes (no regression).
- fib(28) and string_ops bench show no measurable perf delta vs main
(within ~1% noise floor; exception modules are off the hot path).
- Defensive: when raised outside a Lua execution, current_position/0
returns {nil, nil} and exceptions render without a location prefix.
Plan: A19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stdlib bad-argument raises read source position from process dict
Plan:
.agents/plans/A19-error-line-info-native-funcs.mdA18 wired
line/sourcethrough every executor raise and through theassert/errornative-call boundary. This plan finishes the job forevery other stdlib raise —
string.upper(nil),math.floor("x"),table.insertwith bad pos, etc.The implementation strategy turned out cleaner than the plan
anticipated: instead of touching ~80 raise sites individually, the
four exception modules (
RuntimeError,TypeError,AssertionError,ArgumentError) now auto-populate:line/:sourcefromLua.VM.Executor.current_position/0insideexception/1when notgiven explicitly. Zero callsite changes for the ~80
ArgumentErrorraises across
math,string,table, and the rest of stdlib.Explicit opts still win — every executor raise site that already
passes
:line/:source(thesafe_*helpers, thedivide-by-zero / modulo-by-zero sites) is unaffected.
ArgumentErrorgains:line/:source/:call_stackfields andnow renders through
Lua.VM.ErrorFormatterso theat <source>:<line>:prefix shows up consistently with the otherexception types.
Success criteria
mix testpasses (1577 → 1585, +8 new tests inerror_messages_test).mix test --only lua53passes 5/29 (no regression).string.upper(nil)→ TypeError with line/source.table.insert(t, nil, 5)(bad pos) → has line/source.math.floor("x")→ has line/source.Re-ran fib(28) and a 1000-iteration string-ops workload on
both
mainand this branch with a fresh build each time;medians within ~1% (within the noise floor). Exception module
construction is off the hot path —
Process.getonly fireswhen an exception is actually being constructed.
Tour of new behavior
Defensive behavior
When an exception is raised outside any Lua execution (e.g. someone
calls a stdlib helper directly from Elixir, or constructs the
exception by hand),
current_position/0returns{nil, nil}andthe message just renders without a location prefix:
Files touched
lib/lua/vm/argument_error.ex— added:line/:source/:call_stackfields, auto-populate, render viaErrorFormatter.lib/lua/vm/runtime_error.ex— auto-populate.lib/lua/vm/type_error.ex— auto-populate.lib/lua/vm/assertion_error.ex— auto-populate.test/lua/error_messages_test.exs— 8 new tests under"stdlib bad-argument raises carry line and source".
Out of scope (intentional, per plan)
string.pack/string.unpack"not yet implemented" raisesin
lib/lua/vm/stdlib/string.ex. A25 implements them.introduced by this change:
table.insert(t, nil, 5)reports the wrong arg number in its"bad argument" message (says Pull in code #1, should be Add CI #2). Logged as a
candidate for an A24 sub-plan.
setmetatable(5, {})on line 1 of a script reportsline 0—same
source_lineoff-by-one A18 already flagged.Verification