{"record":{"id":"67eab435f5ba854d","repo":"NationalSecurityAgency/ghidra","slug":"unexpected-argument","errorCode":null,"errorMessage":"Unexpected argument: {}","messagePattern":"Unexpected argument: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java","lineNumber":276,"sourceCode":"\t\t\t\t// although not prefered, allow option value to be specified as --option=value\n\t\t\t\tint ix = optionName.indexOf(\"=\");\n\t\t\t\tif (ix > 1) {\n\t\t\t\t\tvalue = optionName.substring(ix + 1);\n\t\t\t\t\toptionName = optionName.substring(0, ix);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tString option = optionName;\n\n\t\t\tif (optionName.startsWith(\"-\") && !optionName.startsWith(\"--\")) {\n\t\t\t\toption = SHORTCUT_OPTION_MAP.get(optionName); // map option to -- long form\n\t\t\t\tif (option == null) {\n\t\t\t\t\tthrow new IllegalArgumentException(\"Unsupported option use: \" + optionName);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!option.startsWith(\"--\")) {\n\t\t\t\tthrow new IllegalArgumentException(\"Unexpected argument: \" + option);\n\t\t\t}\n\n\t\t\tif (!GLOBAL_OPTIONS.contains(option) && !allowedParams.contains(option)) {\n\t\t\t\tthrow new IllegalArgumentException(\"Unsupported option use: \" + optionName);\n\t\t\t}\n\n\t\t\tif (!VALUE_OPTIONS.contains(option)) {\n\t\t\t\t// option without value arg\n\t\t\t\tif (value != null) {\n\t\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"Unsupported option specification: \" + optionName + \"=\");\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (StringUtils.isBlank(value)) {\n\t\t\t\t// consume next param as option value\n\t\t\t\tif (++i == params.length) {\n\t\t\t\t\tthrow new IllegalArgumentException(\"Missing option value: \" + optionName);\n\t\t\t\t}","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java#L258-L294","documentation":"Thrown when, after shortcut resolution, the resolved `option` token does not start with '--'. This catches bare positional values or stray tokens that appear in the options portion of the command line where an option flag is expected.","triggerScenarios":"A token that does not start with '-' at all (a raw value) reaches the option loop, so `option` stays as the bare token and fails the `option.startsWith(\"--\")` check at line 276.","commonSituations":"Forgetting the option flag before a value (e.g. a port number with no `--port`), placing positional arguments in the wrong slot, or a value whose preceding flag was dropped.","solutions":["Prefix the value with its intended option flag, e.g. `--port 5432`.","Re-check argument ordering: required positional parameters come first, then options.","Confirm no stray tokens leaked in from shell expansion."],"exampleFix":"// before\nbsim control configure myhost 5432\n// after\nbsim control configure myhost --port 5432","handlingStrategy":"validation","validationCode":"// Reject bare tokens that look like values, not options, in the options region.\nfor (String t : optionTokens) {\n    if (!t.startsWith(\"-\")) {\n        System.err.println(\"Unexpected non-option argument: \" + t + \". Did you omit a --flag?\");\n        return;\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    launchable.readOptions(command, params, discard);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Unexpected argument:\")) {\n        System.err.println(\"An option flag may be missing before: \" + e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Always pair a value with its --flag; never pass a bare value in the options region.","Validate that option-region tokens are dash-prefixed before invoking the parser.","Keep positionals and options in the order the tool expects."],"tags":["cli","argument-validation","bsim"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}