[0.16.12] Traceback via pcall
Posted: Mon Jan 01, 2018 6:44 pm
I have been making custom commands which require the use of pcall, to avoid errors crashing the game, but i would like to print these errors to server admins so that i can fix these errors. The problem arose that the stack trace back is diffrent when running headless, this causes every player to desync as a result. In lua it says that pcall will remove the traceback up to the pcall which would avoid the desyncs. Here is the code i used to test this:
Here is what happens when i run the functions and commands when on a headless linux server from a client.
Server has a diffrent path to clients but only before the temp dir.
When it is a lua error there is basic traceback ''attempt to perform arithmetic on a nil value"
When it is a an invalid index on a object there is a full trace back with includes all pcalls "LuaGameScript doesn't contain key invalid_key. stack traceback: [stuff here] [C]: in function 'pcall' [stuff here] [C]: in function 'pcall' [stuff here]"
As these are being ran from a command, and the user input is what will cause the error (in context im using pcall(loadstring(input)) and want to return error), this should not cause a desync.
When I run my script (not shown) the full trace back given by an invalid key causes desyncs but the short traceback given by lua errors does not.
Code: Select all
function _error_invalid_key()
return game.invalid_key
end
function _error_lua_error()
return 1-nil
end
commands.add_command('invalid-key','just for testing',function(event)
local success, err = pcall(_error_invalid_key)
log(err)
game.print(err)
end)
commands.add_command('lua-error','just for testing',function(event)
local success, err = pcall(_error_lua_error)
log(err)
game.print(err)
end)
Results
TL;DRServer has a diffrent path to clients but only before the temp dir.
When it is a lua error there is basic traceback ''attempt to perform arithmetic on a nil value"
When it is a an invalid index on a object there is a full trace back with includes all pcalls "LuaGameScript doesn't contain key invalid_key. stack traceback: [stuff here] [C]: in function 'pcall' [stuff here] [C]: in function 'pcall' [stuff here]"
As these are being ran from a command, and the user input is what will cause the error (in context im using pcall(loadstring(input)) and want to return error), this should not cause a desync.
When I run my script (not shown) the full trace back given by an invalid key causes desyncs but the short traceback given by lua errors does not.
Context see point above
Given that the longer tracebacks are only given when there is a factorio object envolded i am reporting it has a bug, as the longer trace back is not given for the lua errors because of pcall, but factorio objects still give an full traceback even from within a pcall.