{"record":{"id":"8419386a0f16bd56","repo":"cakephp/cakephp","slug":"message","errorCode":null,"errorMessage":"{%message}","messagePattern":"\\{%message\\}","errorType":"exception","errorClass":"Cake\\Console\\Exception\\StopException","httpStatus":null,"severity":"error","filePath":"src/Console/ConsoleIo.php","lineNumber":308,"sourceCode":"        $messageType = 'success';\n        $message = $this->wrapMessageWithType($messageType, $message);\n\n        return $this->out($message, $newlines, $level);\n    }\n\n    /**\n     * Halts the current process with a StopException.\n     *\n     * @param string $message Error message.\n     * @param int $code Error code.\n     * @return never\n     * @throws \\Cake\\Console\\Exception\\StopException\n     */\n    public function abort(string $message, int $code = CommandInterface::CODE_ERROR): never\n    {\n        $this->error($message);\n\n        throw new StopException($message, $code);\n    }\n\n    /**\n     * Wraps a message with a given message type, e.g. <warning>\n     *\n     * @param string $messageType The message type, e.g. \"warning\".\n     * @param array<string>|string $message The message to wrap.\n     * @return array<string>|string The message wrapped with the given message type.\n     */\n    protected function wrapMessageWithType(string $messageType, array|string $message): array|string\n    {\n        if (is_array($message)) {\n            foreach ($message as $k => $v) {\n                $message[$k] = \"<{$messageType}>{$v}</{$messageType}>\";\n            }\n        } else {\n            $message = \"<{$messageType}>{$message}</{$messageType}>\";\n        }","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/Console/ConsoleIo.php#L290-L326","documentation":"ConsoleIo::abort() prints the given message as an error and then throws Cake\\Console\\Exception\\StopException to terminate command execution. It is the standard way for a CakePHP console command to bail out early with a user-facing error message and a non-zero exit code (default CommandInterface::CODE_ERROR). The exception signals the command runner to stop processing.","triggerScenarios":"Calling $io->abort('message') or $io->abort('message', $code) anywhere inside a console command when a precondition fails (e.g. missing file, invalid input, failed connection). Any custom command code that decides execution cannot continue.","commonSituations":"Baking tools aborting when a target path is invalid; commands validating required environment/CLI arguments and aborting; data-import scripts stopping when a source is unreachable; plugins using abort() for unrecoverable states.","solutions":["Inspect the printed error message to identify which precondition failed in your command","Fix the underlying condition (provide the missing argument, file, or correct configuration)","Catch StopException in test code or wrappers that invoke the command programmatically to assert on the exit code/message","Pass a meaningful exit code via the second argument if callers script around exit codes"],"exampleFix":"// before\nif (empty($this->args[0])) {\n    $io->abort('No file given');\n}\n// after\nif (empty($this->args[0])) {\n    $io->error('No file given');\n    $this->abortWithMessage = true; // or simply keep abort() but handle StopException in tests\n}","handlingStrategy":"try-catch","validationCode":"if (!is_readable($configPath)) {\n    throw new \\RuntimeException(\"Config file missing: $configPath\"); // validate before the code path that aborts\n}","typeGuard":null,"tryCatchPattern":"try {\n    $io->abort('Cannot continue');\n} catch (\\Cake\\Console\\Exception\\StopException $e) {\n    // handle stop: log, return exit code\n    return $e->getCode();\n}","preventionTips":["Validate inputs and preconditions before reaching abort() and fail with a clearer exception when appropriate","Keep abort() for user-facing terminal states only","In tests, wrap command execution in try/catch for StopException and assert on the code/message","Use distinct exit codes via the second argument so scripts can branch on failure reason"],"tags":["console","cakephp","stop-exception","command-abort"],"backgroundTag":"invalid-cli-argument","analyzedSha":"1128eba9b09f1946df684811350e26f2cef68fac","analyzedAt":"2026-09-12T12:07:00.388Z","contentChangedAt":"2026-09-12T12:07:00.388Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}