[0.15.16] Misleading error from .set_command()

Bugs that are actually features.
Post Reply
folk
Long Handed Inserter
Long Handed Inserter
Posts: 96
Joined: Fri Mar 03, 2017 5:00 pm
Contact:

[0.15.16] Misleading error from .set_command()

Post by folk »

Hi,

If you attempt to give the following command to a LuaEntity or LuaUnitGroup, you get a very misleading error message in return:

Code: Select all

.set_command({
			type = defines.command.attack_area,
			radius = 40,
			destination = nil,
			distraction = defines.distraction.by_anything,
		})
Note the "destination = nil" part.

You get this message in return:

Code: Select all

bad argument #-1 to 'set_command' (table expected, got nil)
(and yes, I do see the #-1)

Which makes you hunt the code for any place where you could possibly somehow end up doing .set_command(nil). And then you can't find it, and the error still happens. And then you rip out your hair and start verifying all parameters to all commands, and then after 6 days and 6 nights of labor, you figure out the above, make this post, and rest on the 7th day.

I'm joking, of course - it took me literally 3 seconds to figure out my mistake. But I can envision less experienced programmers having a traumatic experience like the above :-P

Thank you!

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

Re: [0.15.16] Misleading error from .set_command()

Post by Rseding91 »

That's the generic error Lua gives when an argument on the top of the stack is not the type it expected.

It's either that or we have to add a *ton* of custom error checking everywhere we parse values and that just doesn't seem worth it to me when the goal is: you don't have errors.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Not a bug”