"Failed to read info.json" on uploaded, yet functional mod
Posted: Tue Jul 18, 2017 2:14 am
by Reika
I sometimes get an issue when uploading a mod to the portal, telling me that it could not read the info.json file. In particular, I have noticed the following:
*How the mod zip is compiled matters; ones compiled with WinRAR have the greatest rate of success
*Editing the zip in an attempt to 'fix' the json usually ends up with a zip with two info.json files. Unexpectedly, these files usually work both on the portal and in game.
*Opening the zip and closing it again can sometimes make it work, more frequently if some no-net-change modification is made (like opening a file within, editing it, saving it, reverting the change, and saving again).
In particular it seems to have a problem with auto-compiled zip files, even though the game itself loads them without issue.
Can someone please explain how the portal's parser works so I can get this working more reliably?
{
"name": "FTweaks",
"version": "0.0.6",
"title": "FTweaks",
"author": "Reika",
"contact": "",
"homepage": "",
"factorio_version": "0.15",
"description": "Tweaks the game to either fix minor issues, add QoL features, or make larger changes to game behavior.",
"dependencies": ["base >= 0.15.0"]
}
EDIT 2:
I opened the jar, opened the json, added a "-" after the '}' and then backspaced, re-saved the file, got two jsons in the zip, and it uploaded fine.
Re: "Failed to read info.json" on uploaded, yet functional mod
Posted: Tue Jul 18, 2017 2:52 am
by Reika
Well, I learned something: The actual code used to compile the zips matters too, and seems to be the deciding factor. In particular, however WinRAR does it always works. Editing the contents of a jar/zip actually repack the whole thing using WinRAR's encoding, which the portal can accept.
public static void zipFolder(String srcFolder, String destZipFile) throws IOException {
ZipOutputStream zip = null;
FileOutputStream fileWriter = null;
fileWriter = new FileOutputStream(destZipFile);
zip = new ZipOutputStream(fileWriter);
addFolderToZip("", srcFolder, zip);
zip.flush();
zip.close();
}
private static void addFileToZip(String path, String srcFile, ZipOutputStream zip) throws IOException {
File folder = new File(srcFile);
if (folder.isDirectory()) {
addFolderToZip(path, srcFile, zip);
}
else {
byte[] buf = new byte[1024];
int len;
FileInputStream in = new FileInputStream(srcFile);
zip.putNextEntry(new ZipEntry(path + "/" + folder.getName()));
while ((len = in.read(buf)) > 0) {
zip.write(buf, 0, len);
}
in.close();
}
}
private static void addFolderToZip(String path, String srcFolder, ZipOutputStream zip) throws IOException {
File folder = new File(srcFolder);
for (String fileName : folder.list()) {
if (path.equals("")) {
addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip);
}
else {
addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip);
}
}
}
In theory they are all supposed to be the same. Why am I getting different results? Is there something weird on the server's end about filesystem encoding or something?
Re: "Failed to read info.json" on uploaded, yet functional mod
Here are a whole bunch - my entire set of mods. All of them were built just now using method 2 (the second non-working one) in the above post (so selected because it procedurally most resembles the working one); I tested and made sure that they were - as expected - rejected by the portal.
Re: "Failed to read info.json" on uploaded, yet functional mod
Posted: Wed Jul 19, 2017 8:50 am
by HanziQ
I see, it is actually not read by zipfile, but with a different method.
The problem is path separators, the ZIP standard requires the use of forward slashes, you are using backshlashes.
Re: "Failed to read info.json" on uploaded, yet functional mod
Posted: Wed Jul 19, 2017 5:44 pm
by Reika
HanziQ wrote:I see, it is actually not read by zipfile, but with a different method.
The problem is path separators, the ZIP standard requires the use of forward slashes, you are using backshlashes.
I call "File.separator", not explicitly calling any one slash type, but I suspect you mean that when run on a Windows machine "File.separator" resolves to "\", which then makes a ZIP where those slash types persist. So, amusingly, the fix for the second solution is to hardcode the "/", and NOT use the "coding standard" of File.separator.
One more case of 'best practice' going straight into the toilet.
Re: "Failed to read info.json" on uploaded, yet functional mod
Posted: Wed Jul 19, 2017 8:08 pm
by HanziQ
Well I find a standard using just 1 type of slashes better, than having to use a variable to determine that.
Re: "Failed to read info.json" on uploaded, yet functional mod
Posted: Wed Jul 19, 2017 9:32 pm
by torne
It's explicitly written in the specification defining the ZIP format that you must always use a literal "'/" for path separators. File.separator is only appropriate when dealing with the current OS's filesystem APIs.
Best practise is to obey the standard for the format you are using
Re: "Failed to read info.json" on uploaded, yet functional mod
Posted: Wed Jul 19, 2017 11:00 pm
by Reika
torne wrote:It's explicitly written in the specification defining the ZIP format that you must always use a literal "'/" for path separators. File.separator is only appropriate when dealing with the current OS's filesystem APIs.
Tell that to the 50+ people (read: basically any time I have ever seen it mentioned) on StackOverflow who swear that slashes of any kind should never be explicitly used and that coding one is worthy of derision comparable to doing this.
Re: "Failed to read info.json" on uploaded, yet functional mod
Posted: Wed Jul 19, 2017 11:29 pm
by DaveMcW
Reika wrote:slashes of any kind should never be explicitly used
public final class Constants {
public static final char ZIP_SEPARATOR = '/';
}
// Do you feel better now?
Re: "Failed to read info.json" on uploaded, yet functional mod
Posted: Thu Jul 20, 2017 4:16 pm
by torne
Reika wrote:Tell that to the 50+ people (read: basically any time I have ever seen it mentioned) on StackOverflow who swear that slashes of any kind should never be explicitly used and that coding one is worthy of derision comparable to doing this.
If I happened to come across that on StackOverflow I would indeed tell them that they are wrong, because they are. As has been emphasised multiple times: this only applies to operating system filesystem APIs. When you're dealing with a protocol, file format, or library that explicitly documents that it uses a particular character for a particular purpose then you must do what its documentation says - you can tell the author of that spec/library/whatever that you think they're wrong and they should change it, if you like (though it's several decades too late to do this for the ZIP format), but you can't just decide you're going to do something else unilaterally and expect it to work.
Re: "Failed to read info.json" on uploaded, yet functional mod
Posted: Thu Jul 27, 2017 4:03 pm
by MarcGamesons
I am sorry if I should have opened my own thread, but I am getting this error message too.
Re: "Failed to read info.json" on uploaded, yet functional mod
Posted: Fri Jul 28, 2017 8:07 am
by DaveMcW
You need to make an unzipped folder named: cheaper_landfill_1.2.0
Then use Windows zip function to zip the entire folder.
Re: "Failed to read info.json" on uploaded, yet functional mod
Posted: Fri Jul 28, 2017 10:45 pm
by MarcGamesons
I am really sorry I packaged it wrong, it happens every other time I update my mod and I spend hours until I notice it every time.
But thanks to everyone that took their time trying to help me, I still can't believe that I did it wrong again... I wrote myself a note so I don't do it wrong the next time
Re: "Failed to read info.json" on uploaded, yet functional mod
Posted: Fri Jul 28, 2017 11:28 pm
by d3x0r
I realize I'm more than a week late but...
Arguing that 'I'm using a windows path separator which only windows understands' is a correct thing to do is horrible wrong when making a cross platform package that factorio can use on linux and mac systems which wouldn't accept backslash as a valid character.
Windows has no problem (internally) using either forward or back slashes; it's only poorly written command line tools and cmd.exe builtin functions that puke when being passed the wrong slash.
Stack overflow encouraging anything other than a universal character that can be used on any file system is a horrible thing for them to do too.
Re: "Failed to read info.json" on uploaded, yet functional mod
Posted: Mon Dec 18, 2017 2:21 pm
by fishycat
I came across this problem, too. I updated a mod for 0.16 and tried to upload it to the mod-portal, but it gave me the info.json error.
Next I looked here and found this thread, oh it is because I use 7-zip maybe. Then I got WinRAR, created a new folder and then zipped it with WinRAR, but again info.json error from mod-portal.
What am I overseeing?
Re: "Failed to read info.json" on uploaded, yet functional mod
Posted: Mon Dec 18, 2017 2:56 pm
by HanziQ
fishycat wrote:I came across this problem, too. I updated a mod for 0.16 and tried to upload it to the mod-portal, but it gave me the info.json error.
Next I looked here and found this thread, oh it is because I use 7-zip maybe. Then I got WinRAR, created a new folder and then zipped it with WinRAR, but again info.json error from mod-portal.
What am I overseeing?
Your info.json is missing a '}' at the end.
Re: "Failed to read info.json" on uploaded, yet functional mod
Posted: Mon Dec 18, 2017 4:04 pm
by fishycat
Sorry, maybe I'm a little dumb here, but my info.json is like all the others
info.json
{
"name": "AlienSpaceScience",
"version": "0.0.4",
"title": "Alien Space Science",
"author": "engin33rguy",
"contact": "engin33rguyplays@gmail.com",
"homepage": "https://mods.factorio.com/mods/engin33r ... ce-science",
"description": "Adds alien artifacts back in to make Space Science.
Updated to 0.16 and edited by fishycat.",
"factorio_version": "0.16",
"dependencies": ["base >= 0.16.0"]
}
There is a } at the end. But for safety I tested it with the next one, and that also failed.
info.json
{
"name": "AlienSpaceScience",
"version": "0.0.4",
"title": "Alien Space Science",
"author": "engin33rguy",
"contact": "engin33rguyplays@gmail.com",
"homepage": "https://mods.factorio.com/mods/engin33r ... ce-science",
"description": "Adds alien artifacts back in to make Space Science.
Updated to 0.16 and edited by fishycat.",
"factorio_version": "0.16",
"dependencies": ["base >= 0.16.0"]
}
}