cakephp/cakephp · error · CakeException

The ` ` formatter does not implement ` `.

Error message

The `%s` formatter does not implement `%s`.

What it means

Debugger::getExportFormatter() resolves the 'exportFormatter' config (class name or 'text'/'html' alias) and instantiates it, then asserts the instance implements FormatterInterface. A configured class that doesn't implement the interface throws CakeException.

Solutions

  1. Make the configured formatter class implement Cake\Error\Debug\FormatterInterface
  2. Point exportFormatter config at a built-in formatter (TextFormatter/HtmlFormatter) instead
  3. Add interface implementation and the required format() methods to your custom class

Example fix

// before
class MyFormatter { public function format($node) { ... } }
Debugger::setConfig('exportFormatter', MyFormatter::class);
// after
use Cake\Error\Debug\FormatterInterface;
class MyFormatter implements FormatterInterface { public function format($node) { ... } public function dump($var, $depth = 0) { ... } }
Debugger::setConfig('exportFormatter', MyFormatter::class);
Defensive patterns

Strategy: type-guard

Validate before calling

$cls = Debugger::getConfig('exportFormatter'); if ($cls && !is_subclass_of($cls, \Cake\Error\Debug\FormatterInterface::class)) { throw new \LogicException("{$cls} must implement FormatterInterface"); }

Type guard

function isValidFormatter(string $class): bool { return is_subclass_of($class, \Cake\Error\Debug\FormatterInterface::class); }

Try / catch

try { $out = Debugger::exportVar($var, 3); } catch (\Cake\Core\Exception\CakeException $e) { Debugger::setConfig('exportFormatter', 'text'); $out = Debugger::exportVar($var, 3); }

Prevention

When it happens

Trigger: Debugger::setConfig('exportFormatter', SomeClass::class) where SomeClass does not implement Cake\Error\Debug\FormatterInterface.

Common situations: Custom formatter written without implementing FormatterInterface; refactoring that dropped the interface; typo pointing at an unrelated class.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at src/Error/Debugger.php:576

     * @unstable This method is not stable and may change in the future.
     * @since 4.1.0
     */
    public function getExportFormatter(): FormatterInterface
    {
        $instance = static::getInstance();
        $class = $instance->getConfig('exportFormatter');
        if (!$class) {
            if (ConsoleFormatter::environmentMatches()) {
                $class = ConsoleFormatter::class;
            } elseif (HtmlFormatter::environmentMatches()) {
                $class = HtmlFormatter::class;
            } else {
                $class = TextFormatter::class;
            }
        }
        $instance = new $class();
        if (!$instance instanceof FormatterInterface) {
            throw new CakeException(sprintf(
                'The `%s` formatter does not implement `%s`.',
                $class,
                FormatterInterface::class,
            ));
        }

        return $instance;
    }

    /**
     * Converts a variable to a string for debug output.
     *
     * *Note:* The following keys will have their contents
     * replaced with `*****`:
     *
     *  - password
     *  - login
     *  - host

View on GitHub (pinned to 1128eba9b0)