{"record":{"id":"3fb1c4092f7becc0","repo":"cakephp/cakephp","slug":"invalid-format-output-format-can-be-text-or-xml","errorCode":null,"errorMessage":"Invalid format. Output format can be text or xml.","messagePattern":"Invalid format\\. Output format can be text or xml\\.","errorType":"exception","errorClass":"Cake\\Console\\Exception\\ConsoleException","httpStatus":null,"severity":"error","filePath":"src/Console/ConsoleOptionParser.php","lineNumber":686,"sourceCode":"     * in the parser.\n     *\n     * @param string $format Define the output format, can be text or XML\n     * @param int $width The width to format user content to. Defaults to 72\n     * @return string Generated help.\n     */\n    public function help(string $format = 'text', int $width = 72): string\n    {\n        $formatter = new HelpFormatter($this);\n        $formatter->setAlias($this->rootName);\n\n        if ($format === 'text') {\n            return $formatter->text($width);\n        }\n        if ($format === 'xml') {\n            return (string)$formatter->xml();\n        }\n\n        throw new ConsoleException('Invalid format. Output format can be text or xml.');\n    }\n\n    /**\n     * Set the root name used in the HelpFormatter\n     *\n     * @param string $name The root command name\n     * @return $this\n     */\n    public function setRootName(string $name)\n    {\n        $this->rootName = $name;\n\n        return $this;\n    }\n\n    /**\n     * Parse the value for a long option out of $this->_tokens. Will handle\n     * options with an `=` in them.","sourceCodeStart":668,"sourceCodeEnd":704,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/Console/ConsoleOptionParser.php#L668-L704","documentation":"ConsoleOptionParser::help($subcommand, $format) only supports 'text' (default) and 'xml' output formats, delegating to HelpFormatter. Any other $format string falls through both checks and throws this ConsoleException.","triggerScenarios":"Calling $parser->help(null, $format) (directly or via HelpFormatter-generated help) with $format not equal to 'text' or 'xml', e.g. 'json', 'yaml', or a typo like 'XML' (case-sensitive comparison).","commonSituations":"Attempts to render CLI help as JSON for machine consumption; passing a user/config-supplied format string straight through; case mistakes like 'Text' or 'XML'.","solutions":["Use only 'text' or 'xml' as the format argument.","Normalize/whitelist the incoming format: strtolower($format) and default to 'text' for unknown values.","For JSON or other output, get the XML/arrays via $formatter->xml() or $parser->options() and transform it yourself.","Upgrade CakePHP if newer versions add formats; otherwise subclass HelpFormatter for custom rendering."],"exampleFix":"// before\n$help = $parser->help(null, 'json');\n\n// after\n$format = in_array(strtolower($format), ['text', 'xml'], true) ? strtolower($format) : 'text';\n$help = $parser->help(null, $format);","handlingStrategy":"validation","validationCode":"$allowed = ['text', 'xml'];\nif (!in_array($format, $allowed, true)) {\n    $format = 'text';\n}","typeGuard":"function normalizeFormat(mixed $format): string {\n    return is_string($format) && in_array(strtolower($format), ['text', 'xml'], true)\n        ? strtolower($format) : 'text';\n}","tryCatchPattern":"try {\n    $help = $parser->help($subcommand, $format);\n} catch (ConsoleException $e) {\n    $help = $parser->help($subcommand, 'text');\n}","preventionTips":["Only pass the literal strings 'text' or 'xml' to help()","Whitelist and lowercase user/config-supplied format values","For JSON output, transform $parser->help(null, 'xml') yourself instead of inventing a format","Add a unit test asserting help rendering for each supported format"],"tags":["cakephp","console","cli","help","invalid-argument-value"],"backgroundTag":"invalid-enum-value","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"}