{"record":{"id":"bda3e7aa7f7c5e98","repo":"apache/maven","slug":"failed-to-parse-command-line-options","errorCode":null,"errorMessage":"Failed to parse command line options: {}","messagePattern":"Failed to parse command line options: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnsh/ShellParser.java","lineNumber":31,"sourceCode":" * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied.  See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\npackage org.apache.maven.cling.invoker.mvnsh;\n\nimport org.apache.commons.cli.ParseException;\nimport org.apache.maven.api.cli.Options;\nimport org.apache.maven.cling.invoker.BaseParser;\n\npublic class ShellParser extends BaseParser {\n    @Override\n    protected Options parseCliOptions(LocalContext context) {\n        try {\n            return CommonsCliShellOptions.parse(context.parserRequest.args().toArray(new String[0]));\n        } catch (ParseException e) {\n            throw new IllegalArgumentException(\"Failed to parse command line options: \" + e.getMessage(), e);\n        }\n    }\n}\n","sourceCodeStart":13,"sourceCodeEnd":35,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnsh/ShellParser.java#L13-L35","documentation":"Starting the Maven interactive shell (mvnsh) failed at option parsing: ShellParser parses the shell launcher's own arguments with CommonsCliShellOptions and rethrows any ParseException as IllegalArgumentException 'Failed to parse command line options'. Main Maven build options are not involved; only flags passed to the shell launcher are.","triggerScenarios":"Passing build-style flags (-D, -pl, -am) to the shell launcher, an unrecognized long option, or a flag missing its value.","commonSituations":"Shell aliases/wrappers that append build options to every Maven-family command including `mvn sh`; flags copy-pasted from mvn usage.","solutions":["Run the shell launcher's help to see accepted options.","Strip build options from the invocation and set them inside the shell session instead.","Fix the specific token named in the message."],"exampleFix":"# before: build flags passed to the shell launcher\nmvn sh -DskipTests -pl app\n\n# after: plain launch; set options inside the shell\nmvn sh","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    new ShellParser().parseCliOptions(context);\n} catch (IllegalArgumentException e) {\n    showShellUsageAndExit(e.getMessage());\n}","preventionTips":["Keep global option injection out of `mvn sh` launches.","Set build options inside the shell session, not on its launcher."],"tags":["maven","mvnsh","shell","cli","argument-parsing"],"backgroundTag":"cli-argument-parsing-failed","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}