Page 1 of 1

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

Posted: Mon Sep 08, 2025 6:54 pm
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

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

Posted: Mon Sep 08, 2025 7:09 pm
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"

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

Posted: Tue Sep 09, 2025 12:12 pm
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.

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

Posted: Tue Sep 09, 2025 4:16 pm
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