fix(stdlib): error(msg, level) blames the caller for level >= 2 - #428
Open
shinyobjectz wants to merge 1 commit into
Open
shinyobjectz wants to merge 1 commit into
shinyobjectz wants to merge 1 commit into
Conversation
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.
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.
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 theerrorcall itself, so the message blamed the library instead of the code that called it.Change
0; the interpreter already recorded the line.errorwalks that stack: level 2 names the line the erroring function was called from, level 3 its caller's line.Side effect: tracebacks from compiled code now show real call lines instead of
:0:. Thestack_overflowgallery 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).