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.
API usage validation
-
- Long Handed Inserter
- Posts: 95
- Joined: Thu May 18, 2017 2:22 pm
- Contact:
Re: API usage validation
Can we say at least the fields defined in the API? It may still be useful to raise this event manually with additional context.
Miniloader — UPS-friendly 1x1 loaders
Bulk Rail Loaders — Rapid train loading and unloading
Beltlayer & Pipelayer — Route items and fluids freely underground
Bulk Rail Loaders — Rapid train loading and unloading
Beltlayer & Pipelayer — Route items and fluids freely underground
Re: API usage validation
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.
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
This was done with 0.18.27: viewtopic.php?p=495226#p495226
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.