{"record":{"id":"f1d7c5ede52c4acc","repo":"elastic/elasticsearch","slug":"74","errorCode":"74","errorMessage":"File [{}] does not exist","messagePattern":"File \\[(.+?)\\] does not exist","errorType":"error_code","errorClass":"UserException","httpStatus":null,"severity":"error","filePath":"distribution/tools/keystore-cli/src/main/java/org/elasticsearch/cli/keystore/AddFileKeyStoreCommand.java","lineNumber":71,"sourceCode":"        if (argumentValues.size() % 2 != 0) {\n            throw new UserException(ExitCodes.USAGE, \"settings and filenames must come in pairs\");\n        }\n\n        final KeyStoreWrapper keyStore = getKeyStore();\n\n        for (int i = 0; i < argumentValues.size(); i += 2) {\n            final String setting = argumentValues.get(i);\n\n            if (keyStore.getSettingNames().contains(setting) && options.has(forceOption) == false) {\n                if (terminal.promptYesNo(\"Setting \" + setting + \" already exists. Overwrite?\", false) == false) {\n                    terminal.println(\"Exiting without modifying keystore.\");\n                    return;\n                }\n            }\n\n            final Path file = getPath(argumentValues.get(i + 1));\n            if (Files.exists(file) == false) {\n                throw new UserException(ExitCodes.IO_ERROR, \"File [\" + file.toString() + \"] does not exist\");\n            }\n\n            keyStore.setFile(setting, Files.readAllBytes(file));\n        }\n\n        keyStore.save(env.configDir(), getKeyStorePassword().getChars());\n    }\n\n    @SuppressForbidden(reason = \"file arg for cli\")\n    private static Path getPath(String file) {\n        return PathUtils.get(file);\n    }\n\n}\n","sourceCodeStart":53,"sourceCodeEnd":86,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/distribution/tools/keystore-cli/src/main/java/org/elasticsearch/cli/keystore/AddFileKeyStoreCommand.java#L53-L86","documentation":"Thrown by `add-file` after the keystore is loaded, when the file path given for a setting does not exist on disk (`Files.exists(file) == false`). It is an IO_ERROR (74) — the path is syntactically accepted but the filesystem lookup fails. The file bytes are read with `Files.readAllBytes`, so the path must point to a readable file.","triggerScenarios":"Passing a relative path that does not resolve against the CLI's working directory; a typo or stale path after files moved; permissions/ownership making the path invisible to the running user; NFS mount not yet attached.","commonSituations":"Storing SSL keys or certificates where the absolute path differs between nodes; containers where the file is not mounted into the keystore tool's filesystem namespace; Ansible tasks referencing a path on the controller rather than the target host.","solutions":["Verify the file exists from the same user and working directory the CLI runs under: `ls -l <path>` and `readlink -f <path>`.","Use an absolute path for the file argument.","Ensure the file is mounted/accessible in the same filesystem namespace (e.g., same Docker container) as the keystore process.","Check the path does not contain unexpanded shell variables or `~`."],"exampleFix":"// before\nbin/elasticsearch-keystore add-file xpack.security.transport.ssl.key ssl.key\n// after\nbin/elasticsearch-keystore add-file xpack.security.transport.ssl.key /etc/elasticsearch/certs/node.key","handlingStrategy":"validation","validationCode":"import java.nio.file.Files;\nimport java.nio.file.Path;\n\nfor (Path p : paths) {\n    if (!Files.exists(p) || !Files.isRegularFile(p)) {\n        throw new IllegalArgumentException(\"Missing or non-regular file: \" + p);\n    }\n    if (!Files.isReadable(p)) {\n        throw new IllegalArgumentException(\"Not readable: \" + p);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    runAddFile(setting, path);\n} catch (UserException e) {\n    if (e.exitCode == ExitCodes.IO_ERROR && e.getMessage().contains(\"does not exist\")) {\n        // pre-validate path, then retry once with absolute resolved path\n    } else throw e;\n}","preventionTips":["Always pass absolute file paths to add-file.","Pre-check existence from the same user/namespace the CLI runs under.","In containers, confirm the file is mounted before invoking."],"tags":["elasticsearch","keystore-cli","filesystem","io-error"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}