Page 1 of 1

[0.15.16] Misleading error from .set_command()

Posted: Wed May 31, 2017 11:56 am
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!

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

Posted: Thu Jun 01, 2017 6:54 am
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.