assert(nil)

User avatar
SegFault22
Member
 
Posts: 870
Joined: Mon May 21, 2012 03:17

assert(nil)

by SegFault22 » Fri Sep 30, 2016 09:07

I'm making a mod that creates functions to be used by other mods for stuff like registering many items/nodes/tools more easily than by writing out every single "minetest.register_*()" call in full (my mod automatically fills in many parameters by using properties stored in tables earlier). There may be some instance where some parameters get passed to a function, said parameters being of the correct type (string expected, got string; table expected, got table) but one or more are not valid, because they were not inserted to some special table which has to contain them along with associated properties. Later during loading, said table will be accessed to look-up properties relevant to specific entries, which would cause a crash if we try to access an index that doesn't exist in the table - this kind of crash is as graceful as, for example, falling down a staircase when you know it is there and are looking straight at it, but decided to assume that the first step was at the same height level as the floor at the top.

Is it more graceful to run "assert(nil)" as soon as the invalid parameter is encountered, or would that make my mod "malware"? I remember from over at the Mneincraft-Forge community, in the past GregTech would change the crafting recipes of other mods, and if any of said mods changed the recipes back, GregTech would intentionally cause a crash by some analogous method to "assert(nil)" (except in java of course), and people said that it's malware because it intentionally causes undesired operation of the system/machine when the user tries to use it.

Is there some better way to force the loading to be stopped, without my mod being called "malware" - or is assert(nil) acceptable for a serious mod?
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: assert(nil)

by rubenwardy » Fri Sep 30, 2016 09:20

error("some readable error message") would be better

it's perfectly fine to throw an error if your functions are misused - that's validation
 

User avatar
SegFault22
Member
 
Posts: 870
Joined: Mon May 21, 2012 03:17

Re: assert(nil)

by SegFault22 » Fri Sep 30, 2016 15:07

rubenwardy wrote:error("some readable error message") would be better

it's perfectly fine to throw an error if your functions are misused - that's validation

Okay, I'll use that wherever assert(<some important parameter>,<error message>) doesn't fit well. I thought error(<error message>) was just a neat way to handle errors without stopping the program (try to work around the error without stopping), but now that I think more about it, that doesn't make sense (if there's an error, the program must stop).

Thank you
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron