info.json handled differently by game and modportal

Place to post guides, observations, things related to modding that are not mods themselves.
Pi-C
Filter Inserter
Filter Inserter
Posts: 303
Joined: Sun Oct 14, 2018 8:13 am
Contact:

info.json handled differently by game and modportal

Post by Pi-C » Wed Sep 11, 2019 10:21 am

When I tried to upload a new mod, it was refused on the modportal because the definition of "name" in info.json contained illegal characters ("+" and "-", not just alphanumeric characters and the underscore). I quickly fixed that by changing the name to something else, rebuilding the zip-file, and resubmitting the mod -- which worked this time. However, when I resumed a game with the new mod copied into the local mods directory, Factorio didn't even start. Why? Because I messed up! I just renamed the mod in info.json, but didn't change the name of the directory and the zip-file.

There are two things that would have helped:
  1. I'd never gotten into the situation in the first place if processing info.json would work the same locally as on the mod portal. The mod version with the illegal characters in its name worked perfectly while I used the local copy I was working on. It's not expected behavior that the same mod can't be submitted to the mod portal. The easiest way to fix this that I can imagine: the local game would run the same checks on info.json as the modportal does and give a warning (or exit with an error) if anything is wrong with it.
  2. An additional test: Read info.json, extract the "name" field, and compare it to the name of the zip-file (without the file extension) and the directory contained in it. Bail out with an error if there is a difference. Obviously, info.json must already be parsed when a mod is submitted -- otherwise, the mod portal wouldn't have known about the illegal characters. So, according to my naive thinking, one more little test shouldn't be hard to implement. :-)
Sorry, if this has been brought up already! I did search the forum, but if there was a similar thread, I haven't found it.

ADDENDUM:
There is no tutorial dedicated to info.json. However, there is a short section on that file here. It's not really detailed, though. This is all it says about the "name" field:
This is the internal name of your mod, it is used to identify your mod in code.
I think it would be a good idea to put up some more information on the Wiki: What characters are not allowed in "name"? What is the correct syntax for dependencies (not just "modname", but also "? modname", "(?) modname", and "! modname")?
Last edited by Pi-C on Wed Sep 11, 2019 11:30 am, edited 1 time in total.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3455
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: info.json handled differently by game and modportal

Post by eradicator » Wed Sep 11, 2019 10:30 am

I'm sure @Sanqui would also prefer to use the exact same code-base for the "copliance testing" of the portal, but as he hasn't done it yet i assume it's not "that easy" (cough).

I wonder how much CPU it would cost "the portal" to actually try and start a new map with just the new mod + dependencies on a headless server every time a new version is uploaded. And notify the author when there's an error during that. But then again i'm against "pseudo intelligent" systems because they usually tend to cause problems somewhere else. (Like, even if this sort of automatic-testing was even remotely realistic :p)
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Pi-C
Filter Inserter
Filter Inserter
Posts: 303
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: info.json handled differently by game and modportal

Post by Pi-C » Wed Sep 11, 2019 11:11 am

eradicator wrote:
Wed Sep 11, 2019 10:30 am
I wonder how much CPU it would cost "the portal" to actually try and start a new map with just the new mod + dependencies on a headless server every time a new version is uploaded. And notify the author when there's an error during that. But then again i'm against "pseudo intelligent" systems because they usually tend to cause problems somewhere else. (Like, even if this sort of au=tomatic-testing was even remotely realistic :p)
I don't expect the portal to start a test game -- that would be absolutely not realistic! What I suggest is just making sure the input is sane, and this should just take a simple string comparison:

Code: Select all

a = $NAME_OF_SUBMITTED_FILE (without version number and extension ".zip")
b = $DIRNAME (top directory in the submitted file, without version number)
b = $name (as read from info.json)
if  ($a != $b) or ($a != $c) then ERROR end
You might say that this would still involve unpacking the mod -- but that must be done already to parse info.json.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3455
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: info.json handled differently by game and modportal

Post by eradicator » Wed Sep 11, 2019 11:14 am

Pi-C wrote:
Wed Sep 11, 2019 11:11 am

Code: Select all

a = $NAME_OF_SUBMITTED_FILE (without version number and extension ".zip")
b = $DIRNAME (top directory in the submitted file, without version number)
b = $name (as read from info.json)
if  ($a != $b) or ($a != $c) then ERROR end
The "top directory" can be any name, it doesn't affect anything. (Also you got a double "b" :p).
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Pi-C
Filter Inserter
Filter Inserter
Posts: 303
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: info.json handled differently by game and modportal

Post by Pi-C » Wed Sep 11, 2019 11:21 am

eradicator wrote:
Wed Sep 11, 2019 11:14 am
The "top directory" can be any name, it doesn't affect anything.
Really? How about if you have the mod installed not as a zip-file, but as an unpacked directory? (That should only be relevant if you're working on that mod locally.) I seem to remember that the game wouldn't load in this case if the directory differed from the mod name.
(Also you got a double "b" :p).
Just to show how easy it is to make a mess of even the most simple things, naturally! :-D
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Bilka
Factorio Staff
Factorio Staff
Posts: 2117
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: info.json handled differently by game and modportal

Post by Bilka » Wed Sep 11, 2019 11:44 am

Pi-C wrote:
Wed Sep 11, 2019 10:21 am
ADDENDUM:
There is no tutorial dedicated to info.json. However, there is a short section on that file here. It's not really detailed, though. This is all it says about the "name" field:
This is the internal name of your mod, it is used to identify your mod in code.
I think it would be a good idea to put up some more information on the Wiki: What characters are not allowed in "name"? What is the correct syntax for dependencies (not just "modname", but also "? modname", "(?) modname", and "! modname")?
On my todo for this week :)

Though, for all I know, + and - should be allowed in mod names.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Pi-C
Filter Inserter
Filter Inserter
Posts: 303
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: info.json handled differently by game and modportal

Post by Pi-C » Wed Sep 11, 2019 11:59 am

Bilka wrote:
Wed Sep 11, 2019 11:44 am
Pi-C wrote:
Wed Sep 11, 2019 10:21 am
I think it would be a good idea to put up some more information on the Wiki: What characters are not allowed in "name"? What is the correct syntax for dependencies (not just "modname", but also "? modname", "(?) modname", and "! modname")?
On my todo for this week :)
Thank you!
Though, for all I know, + and - should be allowed in mod names.
I just restored the old version with the invalid name and tried to resubmit it. Here's the error message:
invalid_modname.png
invalid_modname.png (84.07 KiB) Viewed 161 times
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Pi-C
Filter Inserter
Filter Inserter
Posts: 303
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: info.json handled differently by game and modportal

Post by Pi-C » Wed Sep 11, 2019 12:08 pm

Pi-C wrote:
Wed Sep 11, 2019 11:21 am
eradicator wrote:
Wed Sep 11, 2019 11:14 am
The "top directory" can be any name, it doesn't affect anything.
Really? How about if you have the mod installed not as a zip-file, but as an unpacked directory? (That should only be relevant if you're working on that mod locally.) I seem to remember that the game wouldn't load in this case if the directory differed from the mod name.
In this case, the mod is not in an archive, but just in an unpacked directory. Directory name and mod name as defined in info.json are different. This results in an error:
wrong_dirname.png
wrong_dirname.png (144.88 KiB) Viewed 158 times
However, the name of the top directory inside a zip-file really doesn't matter!
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3455
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: info.json handled differently by game and modportal

Post by eradicator » Wed Sep 11, 2019 1:06 pm

Pi-C wrote:
Wed Sep 11, 2019 12:08 pm
However, the name of the top directory inside a zip-file really doesn't matter!
And that is all i said. Sorry if it wasn't clear.
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Pi-C
Filter Inserter
Filter Inserter
Posts: 303
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: info.json handled differently by game and modportal

Post by Pi-C » Wed Sep 11, 2019 1:35 pm

eradicator wrote:
Wed Sep 11, 2019 1:06 pm
Pi-C wrote:
Wed Sep 11, 2019 12:08 pm
However, the name of the top directory inside a zip-file really doesn't matter!
And that is all i said. Sorry if it wasn't clear.
OK, got that now. Except, I don't see a use case for that, based on my personal experience. When I make a mod, I create a new directory with the correct name and version (or just copy the contents of the current version and rename it so the directory name ends with the new version number, if I update an existing mod). This way, I can keep all files open in the editor and make changes wherever I like, and test directly without loading error. Once I've updated name and version in info.json, I've laid the ground for testing the mod with Factorio. When I think I'm done, I just use zip to pack it, and the autocompletion of my shell makes it easy to use the directory's name for the zip-file. So using the same name for top directory and zip-file seems just logical and natural.

The only case I could think of where it would make sense to rename the top directory inside the archive would be as a stupid "security" or DRM feature (about as effective as using JavaScript on a web page to prevent copying text by turning off right-clicking): Don't you dare unpacking my mod -- it won't run anyway if you do it! But perhaps I'm blind to something … :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3455
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: info.json handled differently by game and modportal

Post by eradicator » Wed Sep 11, 2019 1:55 pm

Pi-C wrote:
Wed Sep 11, 2019 1:35 pm
OK, got that now. Except, I don't see a use case for that, based on my personal experience.
Again, just describing how it works now. Though "i don't need it" is very weak reason to argue against anything :p.
Personally all my mods are in a /dev folder, and from there i have directory junctions to the factorio /mods folder. So the root path of all my mods never changes. I only have to rename the junction when i change the version of a mod. The mod folders in the /dev folder do not have version numbers. So for a new release i could just zip them up and add the version number to the zip file name, so the "top directory" inside the zip would be the modname, but without the version number. Ofc automation is king and so i have a build script that does add the version number, but if i didn't it'd be useful ;).
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Pi-C
Filter Inserter
Filter Inserter
Posts: 303
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: info.json handled differently by game and modportal

Post by Pi-C » Wed Sep 11, 2019 2:43 pm

eradicator wrote:
Wed Sep 11, 2019 1:55 pm
Pi-C wrote:
Wed Sep 11, 2019 1:35 pm
OK, got that now. Except, I don't see a use case for that, based on my personal experience.
Again, just describing how it works now. Though "i don't need it" is very weak reason to argue against anything :p.
I didn't want to argue against that, I said that -- based on my personal experience -- I don't understand it. You could use pliers to put on your trousers if you want to: You probably will be able to do this just as well as I do it without pliers, given enough time to practice. If you just told me you used pliers for that I might consider it peculiar because it's something beyond the horizon of my experience. Then again, you might have very good reasons to do so, and if you explain the reason, I might even think of learning how to use pliers to put on my trousers! However, even if you didn't convince me I wouldn't dream of banning you from using pliers to that end. If it suits you, why not? :-)
Personally all my mods are in a /dev folder, and from there i have directory junctions to the factorio /mods folder. So the root path of all my mods never changes. I only have to rename the junction when i change the version of a mod. The mod folders in the /dev folder do not have version numbers. So for a new release i could just zip them up and add the version number to the zip file name, so the "top directory" inside the zip would be the modname, but without the version number. Ofc automation is king and so i have a build script that does add the version number, but if i didn't it'd be useful ;).
This seems like a very good reason for having a different directory name! I've already found one weak point in my workflow: Keeping version numbers, mod name etc. in sync everywhere they are needed can be a chore (I even uploaded a mod with a broken changelog because I forgot to change version and date after copying the header!). Automating this would make sense -- I'll probably fiddle around with that later on. But I'm afraid we're getting off topic again. :-D
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Bilka
Factorio Staff
Factorio Staff
Posts: 2117
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: info.json handled differently by game and modportal

Post by Bilka » Thu Sep 12, 2019 8:26 pm

Consider the info.json documentation done: https://wiki.factorio.com/Tutorial:Mod_ ... #info.json :)
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3455
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: info.json handled differently by game and modportal

Post by eradicator » Thu Sep 12, 2019 9:21 pm

Bilka wrote:
Thu Sep 12, 2019 8:26 pm
Consider the info.json documentation done: https://wiki.factorio.com/Tutorial:Mod_ ... #info.json :)
Oh, new stuff! /me takes out nit-picking-kit
  1. The example should contain a dependency = {} to the base mod! Total conversions don't exist (yet). And as it's the only table in there it'd be nice to have an example for people unfamiliar with JSON (i.e. me).
  2. Eh...that's about it. Looks great. Maybe a sentence about valid JSON requiring that there is *no* comma after the last entry in an array (or is that just me constantly falling for that every time i update the dependencies?).
Great work as always. Thanks.
TheWiki wrote: homepage
Type: string
Optional field. [...] Please don't put "None" here,
I need to go now!...
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Pi-C
Filter Inserter
Filter Inserter
Posts: 303
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: info.json handled differently by game and modportal

Post by Pi-C » Fri Sep 13, 2019 1:04 pm

Bilka wrote:
Thu Sep 12, 2019 8:26 pm
Consider the info.json documentation done: https://wiki.factorio.com/Tutorial:Mod_ ... #info.json :)
Thank you, this looks quite helpful! :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Pi-C
Filter Inserter
Filter Inserter
Posts: 303
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: info.json handled differently by game and modportal

Post by Pi-C » Fri Sep 13, 2019 1:17 pm

eradicator wrote:
Thu Sep 12, 2019 9:21 pm
  • Eh...that's about it. Looks great. Maybe a sentence about valid JSON requiring that there is *no* comma after the last entry in an array (or is that just me constantly falling for that every time i update the dependencies?).
Nope, that usually happens to me as well. But an error in info.json results in an error quite early after starting the game, with a very clear error message. It's still a nuisance, but only a slight one. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3455
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: info.json handled differently by game and modportal

Post by eradicator » Fri Sep 13, 2019 1:58 pm

Pi-C wrote:
Fri Sep 13, 2019 1:17 pm
Nope, that usually happens to me as well. But an error in info.json results in an error quite early after starting the game, with a very clear error message.
An error in json parsing usually leads to the mod being completely ignored as if it didn't exist. And if there's an error message it's buried in the log file. Well, at least i'm not the only one suffering from this ;).
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Pi-C
Filter Inserter
Filter Inserter
Posts: 303
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: info.json handled differently by game and modportal

Post by Pi-C » Fri Sep 13, 2019 2:14 pm

eradicator wrote:
Fri Sep 13, 2019 1:58 pm
An error in json parsing usually leads to the mod being completely ignored as if it didn't exist. And if there's an error message it's buried in the log file.
Oh, damn, you're right of course! The game doesn't crash, but the mod isn't loaded -- alas, there is a clear error message in the log file! For my excuse: I've been offline for more than 36 hours before my last reply, and I'm still not at home now, so I can't load the game to check. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Bilka
Factorio Staff
Factorio Staff
Posts: 2117
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: info.json handled differently by game and modportal

Post by Bilka » Fri Sep 13, 2019 5:44 pm

eradicator wrote:
Thu Sep 12, 2019 9:21 pm
The example should contain a dependency = {} to the base mod! Total conversions don't exist (yet). And as it's the only table in there it'd be nice to have an example for people unfamiliar with JSON (i.e. me).
Since the default dependency is the base mod, showing it in the example would be bad practice in my opinion. So I added a different example to the dependencies descriptions. Yay for that being the only nitpick (I care about) :)
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3455
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: info.json handled differently by game and modportal

Post by eradicator » Fri Sep 13, 2019 6:10 pm

Bilka wrote:
Fri Sep 13, 2019 5:44 pm
Since the default dependency is the base mod, showing it in the example would be bad practice in my opinion. So I added a different example to the dependencies descriptions. Yay for that being the only nitpick (I care about) :)
Hm. Maybe i'm looking at it from the wrong perspective. I see the "example" as something that a beginner can copy/paste into his file and use it and it actually works correctly. But without a dependency to the base mod it's technically incomplete, as every mod depends on base and most are incompatible if you so much as jump back ~5-10 minor versions. Granted it's a very nitpicky nitpick, but my nit-picking-kit has tools for all the small jobs too ;).

The example in the dependencies section is a great addition too though, even if it doesn't showcase my favouritie - the conspiratory dependency "(?)" :p. (Some day i'll learn to just say "thanks" without a "but". Today is not that day *cough*)
Last edited by eradicator on Fri Sep 13, 2019 6:13 pm, edited 1 time in total.
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding discussion”

Who is online

Users browsing this forum: No registered users