{"record":{"id":"11caa025f799c472","repo":"cakephp/cakephp","slug":"the-s-formatter-does-not-implement-s","errorCode":null,"errorMessage":"The `%s` formatter does not implement `%s`.","messagePattern":"The `(.+?)` formatter does not implement `(.+?)`\\.","errorType":"exception","errorClass":"CakeException","httpStatus":null,"severity":"error","filePath":"src/Error/Debugger.php","lineNumber":576,"sourceCode":"     * @unstable This method is not stable and may change in the future.\n     * @since 4.1.0\n     */\n    public function getExportFormatter(): FormatterInterface\n    {\n        $instance = static::getInstance();\n        $class = $instance->getConfig('exportFormatter');\n        if (!$class) {\n            if (ConsoleFormatter::environmentMatches()) {\n                $class = ConsoleFormatter::class;\n            } elseif (HtmlFormatter::environmentMatches()) {\n                $class = HtmlFormatter::class;\n            } else {\n                $class = TextFormatter::class;\n            }\n        }\n        $instance = new $class();\n        if (!$instance instanceof FormatterInterface) {\n            throw new CakeException(sprintf(\n                'The `%s` formatter does not implement `%s`.',\n                $class,\n                FormatterInterface::class,\n            ));\n        }\n\n        return $instance;\n    }\n\n    /**\n     * Converts a variable to a string for debug output.\n     *\n     * *Note:* The following keys will have their contents\n     * replaced with `*****`:\n     *\n     *  - password\n     *  - login\n     *  - host","sourceCodeStart":558,"sourceCodeEnd":594,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/Error/Debugger.php#L558-L594","documentation":"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.","triggerScenarios":"Debugger::setConfig('exportFormatter', SomeClass::class) where SomeClass does not implement Cake\\Error\\Debug\\FormatterInterface.","commonSituations":"Custom formatter written without implementing FormatterInterface; refactoring that dropped the interface; typo pointing at an unrelated class.","solutions":["Make the configured formatter class implement Cake\\Error\\Debug\\FormatterInterface","Point exportFormatter config at a built-in formatter (TextFormatter/HtmlFormatter) instead","Add interface implementation and the required format() methods to your custom class"],"exampleFix":"// before\nclass MyFormatter { public function format($node) { ... } }\nDebugger::setConfig('exportFormatter', MyFormatter::class);\n// after\nuse Cake\\Error\\Debug\\FormatterInterface;\nclass MyFormatter implements FormatterInterface { public function format($node) { ... } public function dump($var, $depth = 0) { ... } }\nDebugger::setConfig('exportFormatter', MyFormatter::class);","handlingStrategy":"type-guard","validationCode":"$cls = Debugger::getConfig('exportFormatter'); if ($cls && !is_subclass_of($cls, \\Cake\\Error\\Debug\\FormatterInterface::class)) { throw new \\LogicException(\"{$cls} must implement FormatterInterface\"); }","typeGuard":"function isValidFormatter(string $class): bool { return is_subclass_of($class, \\Cake\\Error\\Debug\\FormatterInterface::class); }","tryCatchPattern":"try { $out = Debugger::exportVar($var, 3); } catch (\\Cake\\Core\\Exception\\CakeException $e) { Debugger::setConfig('exportFormatter', 'text'); $out = Debugger::exportVar($var, 3); }","preventionTips":["Implement FormatterInterface on any custom formatter","Prefer the built-in aliases ('text'/'html') over raw class names","Add a boot-time assertion in tests that the configured formatter is valid"],"tags":["debugger","formatter","interface"],"backgroundTag":"type-mismatch","analyzedSha":"1128eba9b09f1946df684811350e26f2cef68fac","analyzedAt":"2026-09-12T12:07:00.388Z","contentChangedAt":"2026-09-12T12:07:00.388Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}