apache/hadoop · error · ServiceLaunchException
EXIT_COMMAND_ARGUMENT_ERROR(40)
EXIT_COMMAND_ARGUMENT_ERROR(40)
Error message
Failed to parse: %s
What it means
Thrown by ServiceLauncher when GenericOptionsParser reports an unsuccessful parse (parser.isParseSuccessful() == false) of the command line used to launch a Hadoop service. The launcher aborts with ServiceLaunchException carrying exit code 40 (EXIT_COMMAND_ARGUMENT_ERROR) and substitutes the full quoted argument string (built as "arg" "arg" ...) into the %s placeholder. This is the standard 'bad command line' exit for anything started through the hadoop service-launcher machinery.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/service/launcher/ServiceLauncher.java:933
* @throws ServiceLaunchException if processing of arguments failed
*/
protected List<String> parseCommandArgs(Configuration conf,
List<String> args) {
Preconditions.checkNotNull(commandOptions,
"Command options have not been created");
StringBuilder argString = new StringBuilder(args.size() * 32);
for (String arg : args) {
argString.append("\"").append(arg).append("\" ");
}
LOG.debug("Command line: {}", argString);
try {
String[] argArray = args.toArray(new String[args.size()]);
// parse this the standard way. This will
// update the configuration in the parser, and potentially
// patch the user credentials
GenericOptionsParser parser = createGenericOptionsParser(conf, argArray);
if (!parser.isParseSuccessful()) {
throw new ServiceLaunchException(EXIT_COMMAND_ARGUMENT_ERROR,
E_PARSE_FAILED + " %s", argString);
}
CommandLine line = parser.getCommandLine();
List<String> remainingArgs = Arrays.asList(parser.getRemainingArgs());
LOG.debug("Remaining arguments {}", remainingArgs);
// Scan the list of configuration files
// and bail out if they don't exist
if (line.hasOption(ARG_CONF)) {
String[] filenames = line.getOptionValues(ARG_CONF);
verifyConfigurationFilesExist(filenames);
// Add URLs of files as list of URLs to load
for (String filename : filenames) {
File file = new File(filename);
LOG.debug("Configuration files {}", file);
confResourceUrls.add(file.toURI().toURL());
}
}View on GitHub (pinned to 2add963021)
Solutions
- Read the echoed argument string in the message and locate the offending token, then fix or remove it
- Re-run the service with -help/-h to list the options this launcher actually accepts
- Verify every -D token has the form -Dkey=value and every value-taking option has its value
- In bash scripts use arrays and drop empty variables (e.g. ${VAR:+-Dk=${VAR}}) instead of passing empty strings
Example fix
# before hadoop $SERVICE -Dmapreduce.job.name -files data.csv # after (option value present, -files points at an existing file) hadoop $SERVICE -Dmapreduce.job.name=nightly -files data.csv
Defensive patterns
Strategy: try-catch
Try / catch
try {
int exit = ServiceLauncher.main(serviceName, args);
} catch (ServiceLaunchException e) {
if (e.getExitCode() == ServiceLaunchException.EXIT_COMMAND_ARGUMENT_ERROR) {
// bad argv: the message echoes the full quoted argument string
System.err.println("Bad command line: " + e.getMessage());
printUsage();
} else {
throw e;
}
} Prevention
- Assemble CLI arguments in bash arrays and quote each element
- Drop empty variables instead of passing them (${VAR:+-Dk=${VAR}})
- Smoke-test new or upgraded commands with -help before putting them in scripts
When it happens
Trigger: Running `hadoop <service> ...` (or any launcher built on ServiceLauncher) with an unknown option, an option that expects a value as the last token, a -D token missing its '=' sign, or shell quoting that merges/splits arguments so the parser rejects the argv.
Common situations: Shell scripts interpolating unset or empty variables into CLI flags; option names that changed between Hadoop releases; commands copy-pasted from docs of a different version; unquoted arguments containing spaces.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- 40
- 44
- option {} requires 1 argument.
- "{}" is not a valid value for a quota.
- Storage type {} is not available. Available storage types ar
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/35d120e8e3f334fa.
Report an issue: GitHub.