Skip to content

WebExceptionRenderer logs MissingTemplateException warning for every non-Cake exception in debug mode #19615

Description

@andrii-pukhalevych

Description

Description

With debug = true, rendering any exception that has no matching template in templates/Error/ (e.g. TypeError, ValueError, RuntimeException) writes a warning to the
cake.error log scope:

warning: MissingTemplateException - Failed to render error template `typeError` . Error: Template file `Error/type_error.php` could not be found.

The error page itself renders fine (falls back to error500), so this is only log noise, but it fires for basically every uncaught PHP error during development.

Cause

WebExceptionRenderer::_template() returns the exception-derived method name (typeError) as the template name in debug mode without checking whether such a template exists.
_outputMessage() then calls render('typeError'), catches the resulting MissingTemplateException, logs a warning and re-renders error500.

The warning was introduced in bcacc667cb ("Add logging to error rendering failures"). Logging is useful when a template that should exist is missing (e.g. a broken error500.php), but the fallback from an exception-specific template to error500 is the expected path for all non-Cake exceptions and should not be logged as a problem.

Steps to reproduce

Configure::write('debug', true);
$renderer = new \Cake\Error\Renderer\WebExceptionRenderer(new \TypeError('bad type'), new ServerRequest());
$renderer->render();

Check the cake.error log.

Expected

Either no warning when falling back from a non-existent exception-specific template to error500, or _template() should only return the exception-specific name when the template
actually exists.

Actual

A MissingTemplateException warning is logged on every TypeError / RuntimeException / etc.

CakePHP Version

5.2-5.4

PHP Version

8.3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions