Grasscutters/Grasscutter · error · RuntimeException

Failed to create file.

Error message

Failed to create file.

What it means

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.

Source

Thrown at src/main/java/emu/grasscutter/tools/Dumpers.java:101

                                    };

                            // Add the command info to the list.
                            dump.put(
                                    command.label(),
                                    new CommandInfo(
                                            labels,
                                            description,
                                            List.of(command.usage()),
                                            List.of(command.permission(), command.permissionTargeted()),
                                            command.targetRequirement()));
                        });

        try {
            // Create a file for the dump.
            var file = new File("commands.json");
            if (file.exists() && !file.delete()) throw new RuntimeException("Failed to delete file.");
            if (!file.exists() && !file.createNewFile())
                throw new RuntimeException("Failed to create file.");

            // Write the dump to the file.
            Files.writeString(file.toPath(), JsonUtils.encode(dump));
        } catch (IOException ignored) {
            throw new RuntimeException("Failed to write to file.");
        }
    }

    /**
     * Dumps all avatars to a CSV file.
     *
     * @param locale The language to dump the avatars in.
     */
    static void dumpAvatars(String locale) {
        // Reload resources.
        ResourceLoader.loadAll();
        Language.loadTextMaps();

View on GitHub (pinned to f373827a83)

Solutions

  1. Ensure the working directory is writable and has free disk space.
  2. Check that a directory named commands.json does not already exist (rename or remove it).
  3. Re-run the dumper from a writable directory.
  4. On Windows, verify no permission/ACL blocks file creation in the folder.

Example fix

// before
// chmod a-w . ; java Dumpers -> RuntimeException: Failed to create file.
// after
// chmod u+w . && java Dumpers
Defensive patterns

Strategy: validation

Validate before calling

File dir = new File(".");
if (!dir.canWrite() || dir.getFreeSpace() < 1_000_000)
    throw new IllegalStateException("Working directory not writable or low disk space");
if (new File("commands.json").isDirectory())
    throw new IllegalStateException("commands.json exists as a directory");

Type guard

static boolean canCreate(String name) {
    File f = new File(name);
    return !f.exists() || f.isFile();
}

Try / catch

try {
    dumpCommands();
} catch (RuntimeException e) {
    if ("Failed to create file.".equals(e.getMessage())) {
        LOGGER.warn("Check directory write permission/disk space, then retry.");
    } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Grasscutters/Grasscutter@f373827a83 (2026-09-03). Data as JSON: /api/errors/d1346b6b9207d256. Report an issue: GitHub.