{"record":{"id":"35d120e8e3f334fa","repo":"apache/hadoop","slug":"exit-command-argument-error-40","errorCode":"EXIT_COMMAND_ARGUMENT_ERROR(40)","errorMessage":"Failed to parse:  %s","messagePattern":"Failed to parse:  (.+?)","errorType":"exception","errorClass":"ServiceLaunchException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/service/launcher/ServiceLauncher.java","lineNumber":933,"sourceCode":"   * @throws ServiceLaunchException if processing of arguments failed\n   */\n  protected List<String> parseCommandArgs(Configuration conf,\n      List<String> args) {\n    Preconditions.checkNotNull(commandOptions,\n        \"Command options have not been created\");\n    StringBuilder argString = new StringBuilder(args.size() * 32);\n    for (String arg : args) {\n      argString.append(\"\\\"\").append(arg).append(\"\\\" \");\n    }\n    LOG.debug(\"Command line: {}\", argString);\n    try {\n      String[] argArray = args.toArray(new String[args.size()]);\n      // parse this the standard way. This will\n      // update the configuration in the parser, and potentially\n      // patch the user credentials\n      GenericOptionsParser parser = createGenericOptionsParser(conf, argArray);\n      if (!parser.isParseSuccessful()) {\n        throw new ServiceLaunchException(EXIT_COMMAND_ARGUMENT_ERROR,\n            E_PARSE_FAILED + \" %s\", argString);\n      }\n      CommandLine line = parser.getCommandLine();\n      List<String> remainingArgs = Arrays.asList(parser.getRemainingArgs());\n      LOG.debug(\"Remaining arguments {}\", remainingArgs);\n\n      // Scan the list of configuration files\n      // and bail out if they don't exist\n      if (line.hasOption(ARG_CONF)) {\n        String[] filenames = line.getOptionValues(ARG_CONF);\n        verifyConfigurationFilesExist(filenames);\n        // Add URLs of files as list of URLs to load\n        for (String filename : filenames) {\n          File file = new File(filename);\n          LOG.debug(\"Configuration files {}\", file);\n          confResourceUrls.add(file.toURI().toURL());\n        }\n      }","sourceCodeStart":915,"sourceCodeEnd":951,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/service/launcher/ServiceLauncher.java#L915-L951","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nhadoop $SERVICE -Dmapreduce.job.name -files data.csv\n# after (option value present, -files points at an existing file)\nhadoop $SERVICE -Dmapreduce.job.name=nightly -files data.csv","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  int exit = ServiceLauncher.main(serviceName, args);\n} catch (ServiceLaunchException e) {\n  if (e.getExitCode() == ServiceLaunchException.EXIT_COMMAND_ARGUMENT_ERROR) {\n    // bad argv: the message echoes the full quoted argument string\n    System.err.println(\"Bad command line: \" + e.getMessage());\n    printUsage();\n  } else {\n    throw e;\n  }\n}","preventionTips":["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"],"tags":["cli","argument-parsing","service-launcher","hadoop-common","exit-code-40"],"backgroundTag":"invalid-cli-arguments","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}