oracle/graal · error · InvalidArgumentException

The argument '%s' could not be parsed: invalid command name:

Error message

The argument '%s' could not be parsed: invalid command name: %s

What it means

Thrown by CommandGroup.parse when the first token of a command group does not match any registered subcommand name in its 'commands' map. CommandGroup is itself an Argument placed as a positional, so an unrecognized subcommand is reported as an invalid value of the group argument. Surfaces as InvalidArgumentException with 'invalid command name: <token>'.

Source

Thrown at compiler/src/org.graalvm.profdiff/src/org/graalvm/profdiff/args/CommandGroup.java:107

     * Creates a usage string listing the commands of this group and their help strings.
     *
     * @return the usage string listing the commands
     */
    public String formatCommandsHelp() {
        Formatter fmt = new Formatter();
        fmt.format("available commands:%n");
        for (Command command : commands.getValues()) {
            fmt.format("  %-30s %s%n", command.getName(), command.getDescription());
        }
        return fmt.toString();
    }

    @Override
    int parse(String[] args, int offset) throws InvalidArgumentException, UnknownArgumentException, MissingArgumentException {
        String command = args[offset];
        selectedCommand = commands.get(args[offset]);
        if (selectedCommand == null) {
            throw new InvalidArgumentException(getName(), "invalid command name: " + command);
        }
        selectedCommand.getArgumentParser().parse(Arrays.copyOfRange(args, offset + 1, args.length));
        return args.length;
    }
}

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Print the group's help: it lists 'available commands:' with exact names; use one verbatim.
  2. Check case and hyphenation of the command token.
  3. If embedding, ensure every subcommand you intend to support was registered on the CommandGroup before parse.

Example fix

# before
mx profdiff difftiers --experiment1 a --experiment2 b
# after (exact command name from help)
mx profdiff normal-tier --experiment1 a --experiment2 b
Defensive patterns

Strategy: type-guard

Type guard

// Before invoking, check the subcommand token against the group's commands
boolean known = commandGroup.getCommands().getValues().stream()
    .anyMatch(c -> c.getName().equals(args[0]));

Try / catch

try {
    parser.parse(args);
} catch (InvalidArgumentException e) {
    if (e.getMessage().contains("invalid command name")) { /* print available commands */ }
}

Prevention

When it happens

Trigger: Calling a parser that has a CommandGroup with a token like 'dif' instead of an exact registered command name; case mismatches ('Normal-Tier' vs 'normal-tier'); passing an option where the subcommand name is expected.

Common situations: Typos or abbreviations of profdiff subcommands, renamed commands between GraalVM versions, or shell completion inserting the wrong token.

Related errors


AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14). Data as JSON: /api/errors/df859c2e42211f36. Report an issue: GitHub.