[0.16.12] Traceback via pcall

We are aware of them, but they have low priority. We have more important things to do. They go here in order not to take space in the main bug thread list.
Post Reply
User avatar
Cooldude2606
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Sat Sep 16, 2017 9:04 pm
Contact:

[0.16.12] Traceback via pcall

Post by Cooldude2606 »

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:

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)
Here is what happens when i run the functions and commands when on a headless linux server from a client.
Results
TL;DR
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.
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.
--- Developer for Explosive Gaming factorio community. Find our code on GitHub. Please contact me via our Discord. ---

Rseding91
Factorio Staff
Factorio Staff
Posts: 13218
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.16.12] Traceback via pcall

Post by Rseding91 »

Thanks for the report. At the moment I can't think of any nice way to avoid this.

Simply put: you shouldn't need to use pcall at any point if you've written your mod correctly. If it errors then you should fix what was broken not hide it behind a printed message.

The entire command system the core game uses (any time you type /...) doesn't use any kind of try/catch logic - its simply parses the arguments and returns the appropriate error message.

That being said: it's still something I'd like to prevent if I think of a way to do it in the future. For now I'm going to move this to minor issues.
If you want to get ahold of me I'm almost always on Discord.

quyxkh
Smart Inserter
Smart Inserter
Posts: 1028
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: [0.16.12] Traceback via pcall

Post by quyxkh »

I use pcall for user-supplied console commands, I run them in an environment with handy stuff like `p` as the player, `e` as the selected entity, `b1`, `b2` etc as inventories, ...

User avatar
Cooldude2606
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Sat Sep 16, 2017 9:04 pm
Contact:

Re: [0.16.12] Traceback via pcall

Post by Cooldude2606 »

Rseding91 wrote:That being said: it's still something I'd like to prevent if I think of a way to do it in the future.
Would it be posible to add an event that is rasied when there is a command error rather than crash the game - or this case raise error in pcall, this way there would be no need to us pcall and the error can be handled if wanted. But for now i will find a way to display the error excluding the traceback, thank you you in advanced for looking into this bug.
--- Developer for Explosive Gaming factorio community. Find our code on GitHub. Please contact me via our Discord. ---

Post Reply

Return to “Minor issues”