elastic/elasticsearch · error · UserException

64

64

Error message

the setting names can not be empty

What it means

Thrown by `elasticsearch-keystore add-string` when no positional setting-name arguments are supplied. Like add-file it validates arguments up front with USAGE (64) before opening the keystore. Each supplied name will subsequently prompt for a secret value (or read from stdin with `-x`).

Source

Thrown at distribution/tools/keystore-cli/src/main/java/org/elasticsearch/cli/keystore/AddStringKeyStoreCommand.java:48

    private final OptionSpec<Void> stdinOption;
    private final OptionSpec<String> arguments;

    AddStringKeyStoreCommand() {
        super("Add string settings to the keystore", false);
        this.stdinOption = parser.acceptsAll(Arrays.asList("x", "stdin"), "Read setting values from stdin");
        this.forceOption = parser.acceptsAll(
            Arrays.asList("f", "force"),
            "Overwrite existing setting without prompting, creating keystore if necessary"
        );
        this.arguments = parser.nonOptions("setting names");
    }

    @Override
    protected void executeCommand(Terminal terminal, OptionSet options, Environment env) throws Exception {
        final List<String> settings = arguments.values(options);
        if (settings.isEmpty()) {
            throw new UserException(ExitCodes.USAGE, "the setting names can not be empty");
        }

        final KeyStoreWrapper keyStore = getKeyStore();

        final CheckedFunction<String, char[], IOException> valueSupplier = s -> {
            final String prompt;
            if (options.has(stdinOption)) {
                prompt = "";
            } else {
                prompt = "Enter value for " + s + ": ";
            }
            return terminal.readSecret(prompt);
        };

        for (final String setting : settings) {
            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.");

View on GitHub (pinned to db6a809a66)

Solutions

  1. Provide at least one setting name: `bin/elasticsearch-keystore add-string my.secret`.
  2. To pipe values from stdin, still pass names positionally and add `-x`: `echo $VAL | bin/elasticsearch-keystore add-string -x my.secret`.
  3. In scripts, guard with `[ "$#" -ge 1 ]` or equivalent before calling.

Example fix

// before
bin/elasticsearch-keystore add-string
// after
bin/elasticsearch-keystore add-string my.secret
Defensive patterns

Strategy: validation

Validate before calling

if (settings == null || settings.isEmpty()) {
    throw new IllegalArgumentException("at least one setting name required for add-string");
}

Prevention

When it happens

Trigger: Running `bin/elasticsearch-keystore add-string` bare; an automation template whose setting-name variable is empty; redirecting input expecting the names to come from stdin (they are positional, not stdin).

Common situations: Operators confusing `add-string` with `add-file` semantics; piping a setting name via stdin without `-x`/`--stdin` which only controls the value, not the name.

Related errors


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