{"record":{"id":"6657686d6c73d947","repo":"Grasscutters/Grasscutter","slug":"failed-to-delete-file","errorCode":null,"errorMessage":"Failed to delete file.","messagePattern":"Failed to delete file\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/main/java/emu/grasscutter/tools/Dumpers.java","lineNumber":99,"sourceCode":"                                            this.addAll(List.of(command.aliases()));\n                                        }\n                                    };\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();","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/Grasscutters/Grasscutter/blob/f373827a83d3e688fd3c6afb1e1c3759ca1d61c9/src/main/java/emu/grasscutter/tools/Dumpers.java#L81-L117","documentation":"Thrown by Dumpers.dumpCommands when an existing commands.json cannot be deleted before the dump is recreated. Java's File.delete() returns false (rather than throwing) when deletion fails, so the dumper converts that into an explicit RuntimeException.","triggerScenarios":"Calling dumpCommands while commands.json exists in the working directory and file.delete() returns false — typically the file is locked/open by another process, is read-only, or the process lacks write permission on the directory.","commonSituations":"Having commands.json open in an editor/viewer while running the dump tool; read-only working directory or insufficient permissions; on Windows, antivirus or another process holding a handle to the file.","solutions":["Close any program holding commands.json open (editors, viewers, antivirus scans) and re-run the dump.","Check that the working directory is writable (permissions / not a read-only mount).","Delete commands.json manually if it is stale, then re-run.","Run the tool from a directory where the user has write access."],"exampleFix":"// before\n// $ javac ... && java emu.grasscutter.tools.Dumpers  -> RuntimeException: Failed to delete file.\n// after\n// $ rm -f commands.json && java emu.grasscutter.tools.Dumpers","handlingStrategy":"validation","validationCode":"File file = new File(\"commands.json\");\nif (file.exists() && !file.canWrite()) {\n    System.err.println(\"commands.json is locked or read-only; close it and retry.\");\n    return;\n}","typeGuard":"static boolean canRegenerate(String name) {\n    File f = new File(name);\n    return !f.exists() || (f.isFile() && f.canWrite() && f.delete());\n}","tryCatchPattern":"try {\n    dumpCommands();\n} catch (RuntimeException e) {\n    if (\"Failed to delete file.\".equals(e.getMessage())) {\n        LOGGER.warn(\"Close any program using commands.json and retry.\");\n    } else throw e;\n}","preventionTips":["Keep dump output files closed in editors/spreadsheet tools before running the dumper.","Run the dumper in a user-writable directory.","Exclude the dump directory from antivirus real-time locks if possible.","Delete stale dumps proactively before regenerating."],"tags":["filesystem","io","windows"],"backgroundTag":"file-delete-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"}