cakephp/cakephp · error · Cake\Console\Exception\StopException
{%message}
Error message
{%message} What it means
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.
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
Example fix
// before
if (empty($this->args[0])) {
$io->abort('No file given');
}
// after
if (empty($this->args[0])) {
$io->error('No file given');
$this->abortWithMessage = true; // or simply keep abort() but handle StopException in tests
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!is_readable($configPath)) {
throw new \RuntimeException("Config file missing: $configPath"); // validate before the code path that aborts
} Try / catch
try {
$io->abort('Cannot continue');
} catch (\Cake\Console\Exception\StopException $e) {
// handle stop: log, return exit code
return $e->getCode();
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.
Related errors
- Not creating file. Quitting.
- Short option ` ` is already defined for option ` `. You…
- A required argument cannot follow an optional one
- Missing required argument. The
- Cannot use interactive option prompts without a ConsoleIo…
AI-assisted analysis of cakephp/cakephp@1128eba9b0 (2026-09-12).
Data as JSON: /api/errors/8419386a0f16bd56.
Report an issue: GitHub.
Appendix: source
Thrown at src/Console/ConsoleIo.php:308
$messageType = 'success';
$message = $this->wrapMessageWithType($messageType, $message);
return $this->out($message, $newlines, $level);
}
/**
* Halts the current process with a StopException.
*
* @param string $message Error message.
* @param int $code Error code.
* @return never
* @throws \Cake\Console\Exception\StopException
*/
public function abort(string $message, int $code = CommandInterface::CODE_ERROR): never
{
$this->error($message);
throw new StopException($message, $code);
}
/**
* Wraps a message with a given message type, e.g. <warning>
*
* @param string $messageType The message type, e.g. "warning".
* @param array<string>|string $message The message to wrap.
* @return array<string>|string The message wrapped with the given message type.
*/
protected function wrapMessageWithType(string $messageType, array|string $message): array|string
{
if (is_array($message)) {
foreach ($message as $k => $v) {
$message[$k] = "<{$messageType}>{$v}</{$messageType}>";
}
} else {
$message = "<{$messageType}>{$message}</{$messageType}>";
}View on GitHub (pinned to 1128eba9b0)