elastic/elasticsearch · error · UserException

64

64

Error message

Must provide a single setting name to show

What it means

Thrown by `elasticsearch-keystore show` when the number of positional arguments is not exactly one. Exits USAGE (64). `show` is single-valued by design — it prints exactly one setting's value — so zero or 2+ names are both rejected before the keystore is consulted.

Source

Thrown at distribution/tools/keystore-cli/src/main/java/org/elasticsearch/cli/keystore/ShowKeyStoreCommand.java:47

import java.util.List;

/**
 * A subcommand for the keystore cli to show the value of a setting in the keystore.
 */
public class ShowKeyStoreCommand extends BaseKeyStoreCommand {

    private final OptionSpec<String> arguments;

    public ShowKeyStoreCommand() {
        super("Show a value from the keystore", true);
        this.arguments = parser.nonOptions("setting name");
    }

    @Override
    protected void executeCommand(Terminal terminal, OptionSet options, Environment env) throws Exception {
        final List<String> names = arguments.values(options);
        if (names.size() != 1) {
            throw new UserException(ExitCodes.USAGE, "Must provide a single setting name to show");
        }
        final String settingName = names.get(0);

        final KeyStoreWrapper keyStore = getKeyStore();
        if (keyStore.getSettingNames().contains(settingName) == false) {
            throw new UserException(ExitCodes.CONFIG, "Setting [" + settingName + "] does not exist in the keystore.");
        }

        try (InputStream input = keyStore.getFile(settingName)) {
            final BytesReference bytes = org.elasticsearch.common.io.Streams.readFully(input);
            try {
                byte[] array = BytesReference.toBytes(bytes);
                CharBuffer text = StandardCharsets.UTF_8.newDecoder()
                    .onMalformedInput(CodingErrorAction.REPORT)
                    .onUnmappableCharacter(CodingErrorAction.REPORT)
                    .decode(ByteBuffer.wrap(array));

                // This is not strictly true, but it's the best heuristic we have.

View on GitHub (pinned to db6a809a66)

Solutions

  1. Pass exactly one setting name: `bin/elasticsearch-keystore show my.setting`.
  2. For multiple values, call `show` once per name, or use `list` plus `show` in a loop.
  3. Validate `names.size() == 1` in calling code before invoking.

Example fix

// before
bin/elasticsearch-keystore show s1 s2
// after
bin/elasticsearch-keystore show s1 && bin/elasticsearch-keystore show s2
Defensive patterns

Strategy: validation

Validate before calling

if (names == null || names.size() != 1) {
    throw new IllegalArgumentException("show requires exactly one setting name");
}

Prevention

When it happens

Trigger: Running `show` with no name; passing several names expecting bulk output; a script that always appends a name even when none applies.

Common situations: Operators used to `list` trying to dump multiple values; automation that did not validate count.

Related errors


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