cakephp/cakephp · error · Cake\Core\Exception\CakeException

Loader ` ` in the chain is not a valid callable.

Error message

Loader `%s` in the chain is not a valid callable.

What it means

ChainMessagesLoader iterates its list of loaders and requires each entry to be a valid callable before invoking it. If an entry is not callable (null, string method not resolvable, non-invokable object, array with missing method), it throws CakeException naming the offending index/key.

Solutions

  1. Ensure every loader is a Closure, invokable object, or valid [class/object, method] array
  2. Use is_callable($loader) checks (or fn-first class callable syntax) when building the chain in config
  3. Fix the loader registered via I18n::config() / Translator config to point at an existing method
  4. Dump the chain (var_dump($loaders)) and inspect the index named in the message

Example fix

// before
I18n::config('default', 'App\Loader\MissingLoader'); // string class without __invoke
// after
I18n::config('default', function ($name, $locale) {
    return (new App\Loader\MessagesLoader($locale))->loadPackage($name);
});
Defensive patterns

Strategy: validation

Validate before calling

$loaders = array_filter($this->_loaders, 'is_callable'); // or assert each before invoking

Type guard

function isLoader(mixed $l): bool { return is_callable($l); }

Try / catch

try { $package = $chainLoader(); } catch (\Cake\Core\Exception\CakeException $e) { // log bad loader key from message and fall back to default loader }

Prevention

When it happens

Trigger: Registering a translation loader in the chain as a non-callable value: e.g. a plain string class name lacking __invoke, null where a loader was expected, an array ['Class', 'missingMethod'], or config passing the loader object instead of [$object, 'method'].

Common situations: Misconfigured I18n loaders in bootstrap (I18n::config() with a bad loader); typos in method names; dependency not wired so the loader is null; refactor renamed a loader method.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of cakephp/cakephp@1128eba9b0 (2026-09-12). Data as JSON: /api/errors/87bb3528565fa00a. Report an issue: GitHub.

Appendix: source

Thrown at src/I18n/ChainMessagesLoader.php:56

     * @param array<callable> $loaders List of callables to execute
     */
    public function __construct(array $loaders)
    {
        $this->_loaders = $loaders;
    }

    /**
     * Executes this object returning the translations package as configured in
     * the chain.
     *
     * @return \Cake\I18n\Package
     * @throws \Cake\Core\Exception\CakeException if any of the loaders in the chain is not a valid callable
     */
    public function __invoke(): Package
    {
        foreach ($this->_loaders as $k => $loader) {
            if (!is_callable($loader)) {
                throw new CakeException(sprintf(
                    'Loader `%s` in the chain is not a valid callable.',
                    $k,
                ));
            }

            $package = $loader();
            if (!$package) {
                continue;
            }

            if (!($package instanceof Package)) {
                throw new CakeException(sprintf(
                    'Loader `%s` in the chain did not return a valid Package object.',
                    $k,
                ));
            }

            return $package;

View on GitHub (pinned to 1128eba9b0)