cakephp/cakephp · error · InternalErrorException
Flash message missing.
Error message
Flash message missing.
What it means
FlashComponent::__call() magic methods (e.g. $this->Flash->success(...)) convert the method name into an element name and expect the first argument to be the flash message. When called with zero arguments there is no message to render, so InternalErrorException 'Flash message missing.' is thrown.
Solutions
- Pass the message string as the first argument: $this->Flash->success('Saved.')
- Pass options as the second argument: $this->Flash->success('Saved.', ['params' => ...])
- Use the component's set() method explicitly when you need full control
- Check calls where the message may be a variable that is empty/null — pass a default
Example fix
// before
$this->Flash->error();
// after
$this->Flash->error(__('Could not save record.'), ['clear' => true]); Defensive patterns
Strategy: validation
Validate before calling
if (func_num_args() < 1) {
throw new \LogicException('Flash call requires a message argument');
} Try / catch
try {
$this->Flash->{$type}($message);
} catch (InternalErrorException $e) {
$this->Flash->set('Something happened.');
} Prevention
- Never call magic Flash methods with zero arguments
- Pass message + options in the documented order (message first)
- Route complex flash payloads through FlashComponent::set() instead
When it happens
Trigger: Calling $this->Flash->success() / error() / customElementName() with no arguments, or calling a dynamic flash method with only an options array as the sole argument.
Common situations: Refactoring that removed the message string, intending to set options only but passing them as the first (message) position, typos that route to __call instead of a real method.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Argument ` ` must be an alphanumeric string
- Cannot apply ` ` middleware or middleware group. Use…
- Cannot auto-wire parameter $
- Cannot convert a resource value to JSON
- Cannot convert value
AI-assisted analysis of cakephp/cakephp@1128eba9b0 (2026-09-12).
Data as JSON: /api/errors/777b0999400a684f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Controller/Component/FlashComponent.php:171
*
* Note that the parameter `element` will be always overridden. In order to call a
* specific element from a plugin, you should set the `plugin` option in $args.
*
* For example: `$this->Flash->warning('My message', ['plugin' => 'PluginName'])` would
* use the `warning.php` element under `plugins/PluginName/templates/element/flash/` for
* rendering the flash message.
*
* @param string $name Element name to use.
* @param array $args Parameters to pass when calling `FlashComponent::set()`.
* @return void
* @throws \Cake\Http\Exception\InternalErrorException If missing the flash message.
*/
public function __call(string $name, array $args): void
{
$element = Inflector::underscore($name);
if (count($args) < 1) {
throw new InternalErrorException('Flash message missing.');
}
$options = ['element' => $element];
if (isset($args['options'])) {
$args[1] = $args['options'];
}
if (!empty($args[1])) {
if (!empty($args[1]['plugin'])) {
$options = ['element' => $args[1]['plugin'] . '.' . $element];
unset($args[1]['plugin']);
}
$options += (array)$args[1];
}
$this->set($args[0] ?? $args['message'], $options);
}View on GitHub (pinned to 1128eba9b0)