elastic/elasticsearch · error · UserException

64

64

Error message

Missing setting name

What it means

Thrown by the `elasticsearch-keystore add-file` command when zero positional arguments are supplied. The command expects alternating setting-name / file-path pairs, so a completely empty argument list is rejected up front with a POSIX USAGE (64) exit code. It is a pure client-side argument validation check inside executeCommand before any keystore is opened.

Source

Thrown at distribution/tools/keystore-cli/src/main/java/org/elasticsearch/cli/keystore/AddFileKeyStoreCommand.java:51

    private final OptionSpec<String> arguments;

    AddFileKeyStoreCommand() {
        super("Add a file setting to the keystore", false);
        this.forceOption = parser.acceptsAll(
            Arrays.asList("f", "force"),
            "Overwrite existing setting without prompting, creating keystore if necessary"
        );
        // jopt simple has issue with multiple non options, so we just get one set of them here
        // and convert to File when necessary
        // see https://github.com/jopt-simple/jopt-simple/issues/103
        this.arguments = parser.nonOptions("(setting path)+");
    }

    @Override
    protected void executeCommand(Terminal terminal, OptionSet options, Environment env) throws Exception {
        final List<String> argumentValues = arguments.values(options);
        if (argumentValues.size() == 0) {
            throw new UserException(ExitCodes.USAGE, "Missing setting name");
        }
        if (argumentValues.size() % 2 != 0) {
            throw new UserException(ExitCodes.USAGE, "settings and filenames must come in pairs");
        }

        final KeyStoreWrapper keyStore = getKeyStore();

        for (int i = 0; i < argumentValues.size(); i += 2) {
            final String setting = argumentValues.get(i);

            if (keyStore.getSettingNames().contains(setting) && options.has(forceOption) == false) {
                if (terminal.promptYesNo("Setting " + setting + " already exists. Overwrite?", false) == false) {
                    terminal.println("Exiting without modifying keystore.");
                    return;
                }
            }

            final Path file = getPath(argumentValues.get(i + 1));

View on GitHub (pinned to db6a809a66)

Solutions

  1. Supply at least one setting/path pair on the command line: `bin/elasticsearch-keystore add-file my.setting /path/to/file`.
  2. If scripting, assert the variable is non-empty before invoking: `[ -n "$SETTING" ] && bin/elasticsearch-keystore add-file "$SETTING" "$FILE"`.
  3. Check `add-file --help` to confirm the expected `(setting path)+` non-option syntax.

Example fix

// before
bin/elasticsearch-keystore add-file
// after
bin/elasticsearch-keystore add-file my.setting /etc/es/ssl.key
Defensive patterns

Strategy: validation

Validate before calling

// CLI: validate args before invoking the keystore tool
if (args.isEmpty()) {
    throw new IllegalArgumentException("add-file requires at least one (setting path) pair");
}
if (args.size() % 2 != 0) {
    throw new IllegalArgumentException("add-file requires setting/path pairs");
}

Prevention

When it happens

Trigger: Running `bin/elasticsearch-keystore add-file` with no further tokens; invoking InstallPluginAction-style command wiring that calls AddFileKeyStoreCommand with an empty OptionSet; a wrapper script that forwards a positional list which resolved to nothing.

Common situations: Operators forgetting the required setting and path arguments; misconfigured automation/Ansible that passes an empty variable (e.g. `add-file {{ item }}` with item undefined); shell quoting that swallowed the arguments.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/c59da8ff9a420f04. Report an issue: GitHub.