apache/shardingsphere · error · IllegalArgumentException

Unknown argument: %s

Error message

Unknown argument: %s

What it means

Thrown while parsing command-line options in MCPRegistryMetadataCommand: the argument loop hit a token starting with a case label it does not recognize, so it rejects it with IllegalArgumentException('Unknown argument: ...'). This is strict CLI parsing — no positional or extra flags are tolerated.

Source

Thrown at mcp/registry/src/main/java/org/apache/shardingsphere/mcp/registry/MCPRegistryMetadataCommand.java:137

                    break;
                case "--identifier":
                    identifier = readOptionValue(args, index + 1, "--identifier");
                    index += 2;
                    break;
                case "--dockerfile-path":
                    dockerfilePath = readOptionValue(args, index + 1, "--dockerfile-path");
                    index += 2;
                    break;
                case "--validate-only":
                    validateOnly = true;
                    index++;
                    break;
                case "--allow-snapshot":
                    allowSnapshot = true;
                    index++;
                    break;
                default:
                    throw new IllegalArgumentException("Unknown argument: " + args[index]);
            }
        }
        return new CommandOptions(path, version, identifier, dockerfilePath, validateOnly, allowSnapshot);
    }
    
    private static String readOptionValue(final String[] args, final int index, final String optionName) {
        ShardingSpherePreconditions.checkState(index < args.length && !args[index].startsWith("--"),
                () -> new IllegalArgumentException(optionName + " requires a value."));
        return args[index];
    }
    
    private static void prepareServerJson(final Map<String, Object> server, final String version, final String identifier) {
        server.put("version", version);
        for (Map<String, Object> each : getPackages(server)) {
            each.put("identifier", identifier);
            each.put("version", version);
        }
    }

View on GitHub (pinned to e952770a21)

Solutions

  1. Remove or correct the offending flag; check the command's usage/help for the exact supported option set (--validate-only, --allow-snapshot, --dockerfile-path, etc. in this parser).
  2. Ensure every value-taking option is followed by its value token so the parser does not misalign.
  3. Re-run with only the documented options for your version of the registry command.

Example fix

# before
--dockerfile_path ./Dockerfile
# after
--dockerfile-path ./Dockerfile
Defensive patterns

Strategy: validation

Validate before calling

Set<String> known = Set.of("--path", "--version", "--identifier", "--dockerfile-path", "--validate-only", "--allow-snapshot");
for (int i = 0; i < args.length; i++) { if (args[i].startsWith("--") && !known.contains(args[i])) throw new IllegalArgumentException(args[i]); }

Try / catch

try {
    MCPRegistryMetadataCommand.main(args);
} catch (final IllegalArgumentException ex) {
    // 'Unknown argument: X' -> print usage and exit 2; do not retry the same argv
}

Prevention

When it happens

Trigger: Running the registry metadata command with an unsupported flag (e.g. --output, --verbose) or a misspelled known option (--dockerfile_path instead of --dockerfile-path). Note option values are read positionally, so a missing value can also shift tokens into the flag position and produce this error.

Common situations: Copy-pasting options from other ShardingSphere CLI tools, version skew where an option was added/renamed, or forgetting that value options consume the next token (their value must not start with '--', enforced by readOptionValue).

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/420d1a7dea3a9a79. Report an issue: GitHub.