Page 1 of 1

Providing a useful message for startup errors

Posted: Mon Nov 20, 2017 10:02 pm
by Coppermine
I recall once when I installed a mod and tried to launch Factorio I got an error from that mod during startup (the data*.lua phases) from that mod along the lines of "I noticed you have this other incompatible mod installed; you shouldn't use us both at the same time".

That was very helpful. Now I find myself wanting to do the same with a mod of my own -- that is, provide a useful error message when I detect a fatal configuration issue during startup, and thus pre-empt a load failure with a less useful error that would otherwise occur.

Unfortunately I can't remember in which mod I originally saw this feature, and I can't find anything that would achieve this in the documentation (it's entirely possible I just missed it). Can anyone suggest how to do it?

Re: Providing a useful message for startup errors

Posted: Mon Nov 20, 2017 10:09 pm
by darkfrei
Just adding to info.json

Code: Select all

"dependencies": [
  "base >= 0.15.0",
"  ? mod_name < 0.0.0"
- negative version is not exists, incompatible.

Re: Providing a useful message for startup errors

Posted: Mon Nov 20, 2017 10:13 pm
by Coppermine
Thanks, but the mod incompatibility was just an example. My situation is more complex than that; I need to be able to run arbitrary code in data*.lua and report an error if I detect a problem.

Re: Providing a useful message for startup errors

Posted: Mon Nov 20, 2017 10:31 pm
by posila
In data*.lua you can call error("there seems to be a problem")

Re: Providing a useful message for startup errors

Posted: Mon Nov 20, 2017 10:47 pm
by Coppermine
posila wrote:In data*.lua you can call error("there seems to be a problem")
Perfect! Thanks :D.

Re: Providing a useful message for startup errors

Posted: Mon Nov 20, 2017 11:22 pm
by Rseding91
0.16 also adds incompatible dependencies so in 0.16 you can do this:

Code: Select all

"dependencies": [
"base >= 0.15.0",
"! mod_name"]
and it will trigger your mod to simply be disabled at startup until the given mod is either removed or disabled.