{"record":{"id":"d1346b6b9207d256","repo":"Grasscutters/Grasscutter","slug":"failed-to-create-file","errorCode":null,"errorMessage":"Failed to create file.","messagePattern":"Failed to create file\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/main/java/emu/grasscutter/tools/Dumpers.java","lineNumber":101,"sourceCode":"                                    };\n\n                            // Add the command info to the list.\n                            dump.put(\n                                    command.label(),\n                                    new CommandInfo(\n                                            labels,\n                                            description,\n                                            List.of(command.usage()),\n                                            List.of(command.permission(), command.permissionTargeted()),\n                                            command.targetRequirement()));\n                        });\n\n        try {\n            // Create a file for the dump.\n            var file = new File(\"commands.json\");\n            if (file.exists() && !file.delete()) throw new RuntimeException(\"Failed to delete file.\");\n            if (!file.exists() && !file.createNewFile())\n                throw new RuntimeException(\"Failed to create file.\");\n\n            // Write the dump to the file.\n            Files.writeString(file.toPath(), JsonUtils.encode(dump));\n        } catch (IOException ignored) {\n            throw new RuntimeException(\"Failed to write to file.\");\n        }\n    }\n\n    /**\n     * Dumps all avatars to a CSV file.\n     *\n     * @param locale The language to dump the avatars in.\n     */\n    static void dumpAvatars(String locale) {\n        // Reload resources.\n        ResourceLoader.loadAll();\n        Language.loadTextMaps();\n","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/Grasscutters/Grasscutter/blob/f373827a83d3e688fd3c6afb1e1c3759ca1d61c9/src/main/java/emu/grasscutter/tools/Dumpers.java#L83-L119","documentation":"Thrown by Dumpers.dumpCommands when commands.json does not exist and File.createNewFile() fails to create it. createNewFile() throws checked IOExceptions and returns false only in a race where the file appears concurrently, so this signals the dump file could not be materialized in the working directory.","triggerScenarios":"Calling dumpCommands in a directory where commands.json cannot be created: IOException from createNewFile() (no write permission, path is a directory, disk full) or the file already existing again after the exists() check.","commonSituations":"Running the dumper in a read-only or non-writable directory; disk quota/full disk; commands.json existing as a directory rather than a file; concurrent processes racing on the same file path.","solutions":["Ensure the working directory is writable and has free disk space.","Check that a directory named commands.json does not already exist (rename or remove it).","Re-run the dumper from a writable directory.","On Windows, verify no permission/ACL blocks file creation in the folder."],"exampleFix":"// before\n// chmod a-w . ; java Dumpers -> RuntimeException: Failed to create file.\n// after\n// chmod u+w . && java Dumpers","handlingStrategy":"validation","validationCode":"File dir = new File(\".\");\nif (!dir.canWrite() || dir.getFreeSpace() < 1_000_000)\n    throw new IllegalStateException(\"Working directory not writable or low disk space\");\nif (new File(\"commands.json\").isDirectory())\n    throw new IllegalStateException(\"commands.json exists as a directory\");","typeGuard":"static boolean canCreate(String name) {\n    File f = new File(name);\n    return !f.exists() || f.isFile();\n}","tryCatchPattern":"try {\n    dumpCommands();\n} catch (RuntimeException e) {\n    if (\"Failed to create file.\".equals(e.getMessage())) {\n        LOGGER.warn(\"Check directory write permission/disk space, then retry.\");\n    } else throw e;\n}","preventionTips":["Run tools from a writable working directory (avoid read-only mounts/Program Files).","Ensure adequate free disk space before large dumps.","Never name directories the same as expected output files.","Avoid concurrent dump runs writing the same path."],"tags":["filesystem","io","permissions"],"backgroundTag":"file-create-failed","analyzedSha":"f373827a83d3e688fd3c6afb1e1c3759ca1d61c9","analyzedAt":"2026-09-03T22:43:49.407Z","contentChangedAt":"2026-09-03T22:43:49.407Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}