Improve data:extend's error message (or support the common misuse)

User avatar
PennyJim
Fast Inserter
Fast Inserter
Posts: 131
Joined: Wed Jan 18, 2023 3:49 am
Contact:

Improve data:extend's error message (or support the common misuse)

Post by PennyJim »

A number of times people will see "invalid prototype array" and misinterpret that.
Or even just miss those words entirely because of the big block of text that is the serpent.block of what was given

What I want is to reword it into "invalid array of prototypes" to be a little more clear in what it means, as well as probably throw in a few newlines to separate the block from the error message.


There's also the possibility of just supporting single prototypes being given to the dataloader, but I'll leave that up to you to choose.

Code: Select all

if type(otherdata) ~= table_string then
    error("Invalid array of prototypes:\n\n" .. serpent.block(otherdata, {maxlevel= 1}))
end
if #otherdata == 0 then
    return data:extend({otherdata})
end
User avatar
Osmo
Fast Inserter
Fast Inserter
Posts: 141
Joined: Wed Oct 23, 2024 12:08 pm
Contact:

Re: Improve data:extend's error message (or support the common misuse)

Post by Osmo »

+1, can even do a different error message if the provided table has type or name keys, saying "Expected array of prototypes, got a single protoype"
Bilka
Factorio Staff
Factorio Staff
Posts: 3597
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Improve data:extend's error message (or support the common misuse)

Post by Bilka »

I've improved the errors for 2.0.67. I did not change data:extend to allow a single prototype because that would be a behaviour change that I am not comfortable making at this stage.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
protocol_1903
Filter Inserter
Filter Inserter
Posts: 322
Joined: Fri Sep 09, 2022 4:33 pm
Contact:

Re: Improve data:extend's error message (or support the common misuse)

Post by protocol_1903 »

I feel like only allowing a table input to `data:extend` is fine. Nothing is lost by preventing just one prototype to be input
If you need to reach me, message me on discord.

I make qol mods. Check them out, maybe.
https://mods.factorio.com/user/protocol_1903
If you have a mod idea, I can look into it.
Post Reply

Return to “Implemented mod requests”