Skip to content

fix(stdlib): error(msg, level) blames the caller for level >= 2 - #428

Open
shinyobjectz wants to merge 1 commit into
tv-labs:mainfrom
OpenRelationship:fix/error-level
Open

shinyobjectz wants to merge 1 commit into
tv-labs:mainfrom
OpenRelationship:fix/error-level

Conversation

@shinyobjectz

Copy link
Copy Markdown

error(msg, 2) is how a Lua library reports a caller's mistake. Here the level was read, but every level of 1 or more used the line of the error call itself, so the message blamed the library instead of the code that called it.

Change

  • The dispatcher now records each call's line in its call-stack frame. Before, it recorded 0; the interpreter already recorded the line.
  • error walks that stack: level 2 names the line the erroring function was called from, level 3 its caller's line.
  • A level past the end of the stack omits the prefix, as PUC Lua does.

Side effect: tracebacks from compiled code now show real call lines instead of :0:. The stack_overflow gallery golden is updated to match.

Tests: level 2 and level 3 cases in pcall_error_value_test.exs, run under both engines. The full suite passes (2874 passed).

error's level was read but every level >= 1 used the error's own line, so a
library function's error("bad input", 2) blamed the library, not the code
that called it. The dispatcher now records each call's line in its
call-stack frame (it recorded 0), and error walks the call stack: level 2
names the line the erroring function was called from, level 3 its
caller's, and a level past the stack drops the prefix, as PUC Lua does.
Tracebacks from compiled code show real call lines instead of :0: as a
consequence.
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