Page 1 of 1

[0.16.36] stack trace missing from some Lua errors

Posted: Thu Apr 12, 2018 7:17 am
by Therax

Code: Select all

/c local a = 42 game.print(a[1])
Result:

Code: Select all

Cannot execute command. Error: [string "local a = 42 game.print(a[1])"]:1: attempt to index local 'a' (a number value)
All is well so far. Now try:

Code: Select all

/c local a = {42} game.print(next(a,2)[1])
Result:

Code: Select all

Cannot execute command. Error: invalid key to 'next'
Note that there is no source code listed, and no line number (:1: in the previous example). It looks like there is some case where the Lua message handler isn't being set up properly to capture the debug.traceback.

This is reproduceable in mod script code, which can make tracking down certain types of bugs difficult. Derived from mod bug report here where no traceback was displayed or logged.

Re: [0.16.36] stack trace missing from some Lua errors

Posted: Thu Apr 12, 2018 4:26 pm
by Rseding91
Thanks for the report however there's not much we can do about that.

Those kinds of errors are handled on the Lua side and by the time Factorio error handling knows about the error the stack information is long gone.

Re: [0.16.36] stack trace missing from some Lua errors

Posted: Fri Apr 13, 2018 8:11 pm
by Therax
Rseding91 wrote:Thanks for the report however there's not much we can do about that.

Those kinds of errors are handled on the Lua side and by the time Factorio error handling knows about the error the stack information is long gone.
The standard interpreter seems to handle it just fine via luaL_traceback and lua_pcall():

Code: Select all

Lua 5.2.4  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> function a() next({}, 0) end function b() a() end function c() b() end c()
invalid key to 'next'
stack traceback:
        [C]: in function 'next'
        stdin:1: in function 'a'
        stdin:1: in function 'b'
        stdin:1: in function 'c'
        stdin:1: in main chunk
        [C]: in ?
And Factorio does it correctly for other types of errors. What's different?