{"record":{"id":"12de7f2175070900","repo":"cakephp/cakephp","slug":"argument-s-is-not-defined-on-this-command-could-this-be-an","errorCode":null,"errorMessage":"Argument `%s` is not defined on this Command. Could this be an option maybe?","messagePattern":"Argument `(.+?)` is not defined on this Command\\. Could this be an option maybe\\?","errorType":"exception","errorClass":"Cake\\Console\\Exception\\ConsoleException","httpStatus":null,"severity":"error","filePath":"src/Console/Arguments.php","lineNumber":300,"sourceCode":"     * @param string $name The name of the option to check.\n     * @return bool\n     */\n    public function hasOption(string $name): bool\n    {\n        return isset($this->options[$name]);\n    }\n\n    /**\n     * @param string $name\n     * @return void\n     */\n    protected function assertArgumentExists(string $name): void\n    {\n        if (in_array($name, $this->argNames, true)) {\n            return;\n        }\n\n        throw new ConsoleException(sprintf(\n            'Argument `%s` is not defined on this Command. Could this be an option maybe?',\n            $name,\n        ));\n    }\n}\n","sourceCodeStart":282,"sourceCodeEnd":306,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/Console/Arguments.php#L282-L306","documentation":"Arguments::assertArgumentExists() throws ConsoleException when the requested positional argument name is not defined on the command, hinting the user may have meant an option instead. It is the existence check run at the top of getArgument() and getArrayArgument().","triggerScenarios":"Calling getArgument('foo') or getArrayArgument('foo') where 'foo' is not in $this->argNames — a typo, or reading an option with an argument getter.","commonSituations":"Typos in argument names; confusing arguments with options (e.g. --verbose read via getArgument); renaming an argument without updating the accessor; command class reused across commands with different argument sets.","solutions":["Fix the argument name to match one defined on the command","If it is actually an option, use getOption()/getArrayOption()/getBooleanOption() instead","List defined arguments (e.g. via the command's help or definition code) to confirm exact names"],"exampleFix":"// before\n$opt = $args->getArgument('--verbose');\n// after\n$opt = $args->getBooleanOption('verbose');","handlingStrategy":"validation","validationCode":"// check defined argument names before accessing\nif (!in_array($name, $knownArgNames, true)) {\n    throw new \\InvalidArgumentException(\"Unknown argument '$name' — defined args: \" . implode(', ', $knownArgNames));\n}","typeGuard":"function argOrOption(\\Cake\\Console\\Arguments $a, string $name): string|bool|array|null {\n    return $a->hasArgument($name) // if exposed\n        ? $a->getArgument($name)\n        : $a->getOption($name);\n}","tryCatchPattern":"try {\n    $value = $args->getArgument('target');\n} catch (\\Cake\\Console\\Exception\\ConsoleException $e) {\n    // maybe it's an option\n    $value = $args->getOption('target');\n}","preventionTips":["Copy argument names from the command's definition, never from memory","Rename-safe: define argument name constants and reuse them in accessors","Run `bin/app mycommand --help` to see the exact declared argument names"],"tags":["cli","php","arguments","typo"],"backgroundTag":"missing-required-argument","analyzedSha":"1128eba9b09f1946df684811350e26f2cef68fac","analyzedAt":"2026-09-12T12:07:00.388Z","contentChangedAt":"2026-09-12T12:07:00.388Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}