t8y2/dbx · error · IllegalArgumentException

Unexpected argument:

Error message

Unexpected argument: 

What it means

parse throws IllegalArgumentException when more than one non-flag positional argument is supplied. Only the first bare argument is taken as the Maven coordinate; a second bare token has no meaning and is rejected.

Source

Thrown at plugins/jdbc/src/main/java/app/dbx/jdbc/maven/DbxMavenResolver.java:159

        private static ResolverOptions parse(String[] args) {
            ResolverOptions options = new ResolverOptions();
            for (int index = 0; index < args.length; index++) {
                String arg = args[index];
                switch (arg) {
                    case "resolve" -> {
                    }
                    case "--coordinate", "-c" -> options.coordinate = value(args, ++index, arg);
                    case "--scope" -> options.scope = value(args, ++index, arg).toLowerCase(Locale.ROOT);
                    case "--repo", "--repository" -> options.repositories.add(value(args, ++index, arg));
                    case "--local-repo" -> options.localRepository = Path.of(value(args, ++index, arg));
                    default -> {
                        if (arg.startsWith("-")) {
                            throw new IllegalArgumentException("Unsupported option: " + arg);
                        }
                        if (options.coordinate == null) {
                            options.coordinate = arg;
                        } else {
                            throw new IllegalArgumentException("Unexpected argument: " + arg);
                        }
                    }
                }
            }
            if (options.repositories.isEmpty()) {
                options.repositories.add(DEFAULT_REPOSITORY);
            }
            return options;
        }

        private static String value(String[] args, int index, String option) {
            if (index >= args.length || args[index].isBlank()) {
                throw new IllegalArgumentException(option + " requires a value");
            }
            return args[index];
        }
    }

View on GitHub (pinned to c0390bff16)

Solutions

  1. Provide exactly one coordinate argument; quote values containing spaces
  2. Prefix the second value with its flag, e.g. --repo <url> or --coordinate <g:a:v>
  3. Wrap values with spaces in quotes so they parse as a single argument

Example fix

// before
DbxMavenResolver com.example:foo:1.0 https://repo.example.com/maven2
// after
DbxMavenResolver --repo https://repo.example.com/maven2 com.example:foo:1.0
Defensive patterns

Strategy: validation

Validate before calling

long positionals = Arrays.stream(args).filter(a -> !a.startsWith("-")).count();
if (positionals > 1) {
    throw new IllegalArgumentException("only one coordinate positional allowed");
}

Try / catch

try {
    Options o = Options.parse(args);
} catch (IllegalArgumentException e) {
    System.err.println("Usage: resolver [--repo URL] <group:artifact:version>");
    System.exit(2);
}

Prevention

When it happens

Trigger: Passing two positional values, e.g. 'com.example:foo:1.0 1.2' or forgetting a flag so an intended option value becomes a second positional argument (e.g. 'foo:1.0 com.example:bar:2.0' where the first coordinate was meant to follow --repo).

Common situations: Unquoted values containing spaces; missing a flag so a value like a repository URL is treated as a coordinate; copy-paste of two artifacts into one command.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/ff12e26e6b517fcd. Report an issue: GitHub.