[0.16.36] stack trace missing from some Lua errors

Bugs that are actually features.
User avatar
Therax
Filter Inserter
Filter Inserter
Posts: 471
Joined: Sun May 21, 2017 6:28 pm
Contact:

[0.16.36] stack trace missing from some Lua errors

Post 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.
Miniloader — UPS-friendly 1x1 loaders
Bulk Rail Loaders — Rapid train loading and unloading
Beltlayer & Pipelayer — Route items and fluids freely underground
Rseding91
Factorio Staff
Factorio Staff
Posts: 14373
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Therax
Filter Inserter
Filter Inserter
Posts: 471
Joined: Sun May 21, 2017 6:28 pm
Contact:

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

Post 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?
Miniloader — UPS-friendly 1x1 loaders
Bulk Rail Loaders — Rapid train loading and unloading
Beltlayer & Pipelayer — Route items and fluids freely underground
Post Reply

Return to “Not a bug”