Page 1 of 1

API usage validation

Posted: Tue Apr 02, 2019 3:34 pm
by danielbrauer
I recently encountered a problem where other mods are not correctly passing an entity when raising the script_raised_built event. I can program defensively, but the current situation means every mod developer needs to program defensively just to avoid errors.

It would be super cool if Factorio considered it an error to pass a table to an event which does not have exactly the fields defined in the API.

Re: API usage validation

Posted: Wed Apr 03, 2019 1:55 am
by Therax
Can we say at least the fields defined in the API? It may still be useful to raise this event manually with additional context.

Re: API usage validation

Posted: Thu Apr 04, 2019 10:18 pm
by Boodals
I think you just chalk this up to a broken mod.
I agree that you shouldn't have to check defensively, especially with events that are typically from the game, but if you wanted to enforce it then there's a lot of edge cases it would need to look out for. eg. can you not send optional data? what about events where you get multiple optional data together in a group? if that logic wasn't also enforced you could still break it. In the end, it would be super convoluted and hard to maintain, and it's something so rare that it just wouldn't be worth it.

With script_raised_built I recommend checking for entity or created_entity. Before 0.17 there wasn't an official standard in the api doc, so people used either. I personally use created_entity because that's what all the other on_built events use, but I guess I should change over to entity if that's what the api says.

Re: API usage validation

Posted: Tue Sep 01, 2020 7:45 am
by Bilka
This was done with 0.18.27: viewtopic.php?p=495226#p495226