The website should display the template's standard 404 error page (error.php
). The server should return a 404 HTTP status code, and no "CRITICAL
" error should be logged for a simple page not found event.
A "CRITICAL" error is logged, and the user may be presented with a generic server error page instead of the themed 404 page.
Log Entry:
2025-07-25T15:17:44+00:00 CRITICAL ::1 error Uncaught Throwable of type Joomla\CMS\Router\Exception\RouteNotFoundException thrown with message "Seite nicht gefunden". Stack trace: #0 [ROOT]\libraries\src\Application\SiteApplication.php(767): Joomla\CMS\Router\Router->parse(Object(Joomla\CMS\Uri\Uri), true)
#1 [ROOT]\libraries\src\Application\SiteApplication.php(243): Joomla\CMS\Application\SiteApplication->route()
#2 [ROOT]\libraries\src\Application\CMSApplication.php(304): Joomla\CMS\Application\SiteApplication->doExecute()
#3 [ROOT]\includes\app.php(58): Joomla\CMS\Application\CMSApplication->execute()
#4 [ROOT]\index.php(32): require_once('C:\\Web\\xampp\\ht...')
#5 {main}
The issue originates from how exceptions are handled in the application lifecycle.
A request for a non-existent page causes Joomla\CMS\Application\SiteApplication::route()
to throw a Joomla\CMS\Router\Exception\RouteNotFoundException
.
This exception is not caught within SiteApplication::doExecute()
, so it propagates up the call stack.
It is ultimately caught by the generic catch (\Throwable $throwable
) block within Joomla\CMS\Application\CMSApplication::execute()
.
This top-level exception handler treats all Throwable instances as critical errors, passing them to ExceptionHandler::handleException()
. It does not differentiate a standard 404 condition from a genuine 500-level server error.
The exception handler in CMSApplication::execute()
should maybe be modified to check if the caught exception is an instanceof RouteNotFoundException
and, if so, initiate the proper 404 response (set header, render template's error.php) instead of logging it as a critical failure.
Anyone familiar with that?
Update:
Can anyone verify if this error also occurs on other Joomla sites?
F.e. activate logging and visit your page root/notexistingurl and see if you get the error?
Codebase:
SiteApplication.php
RouteNotFoundException.php
CMSApplication.php
ExceptionHandler.php
Labels |
Added:
No Code Attached Yet
|
@Sunil1532 we don;t assign issues
As I am beginner to open source, I have confused.
I am running into this issue when I try to save an article that has many characters. A 500 error page shows and not a 404.
I am running into this issue when I try to save an article that has many characters. A 500 error page shows and not a 404.
Since you are running into a server error and not a missing website, a 500 error is correct here.
I've been looking into this issue. The current behavior of logging 404 errors as CRITICAL
makes it difficult to distinguish between common "page not found" events and genuine, critical server problems.
I believe a good solution is to modify the ExceptionHandler
to log RouteNotFoundException
events as a concise, single-line NOTICE
instead. This keeps the logs clean while still providing useful information about broken links or scanning attempts.
This can be achieved with a small change to the logException
method in libraries/src/Exception/ExceptionHandler.php
.
First, two use
statements need to be present at the top of ExceptionHandler.php
:
use Joomla\CMS\Router\Exception\RouteNotFoundException;
use Joomla\CMS\Application\Exception\NotAcceptable;
use Joomla\CMS\Uri\Uri;
Then, the logException
method can be updated to differentiate between exception types.
Original logException
method:
protected static function logException(\Throwable $error)
{
// Try to log the error, but don't let the logging cause a fatal error
try {
Log::add(
\sprintf(
'Uncaught Throwable of type %1$s thrown with message "%2$s". Stack trace: %3$s',
\get_class($error),
$error->getMessage(),
$error->getTraceAsString()
),
Log::CRITICAL,
'error'
);
} catch (\Throwable) {
// Logging failed, don't make a stink about it though
}
}
Modified logException
method:
protected static function logException(\Throwable $error)
{
// Handle common client errors as notices instead of critical errors
if ($error instanceof RouteNotFoundException) {
$level = Log::NOTICE;
$message = \sprintf(
'Page not found (404): %s. Message: "%s"',
Uri::getInstance()->toString(),
$error->getMessage()
);
$category = 'client-error';
} elseif ($error instanceof NotAcceptable) {
$level = Log::NOTICE;
$message = \sprintf(
'Not acceptable (406): %s. Message: "%s"',
Uri::getInstance()->toString(),
$error->getMessage()
);
$category = 'client-error';
} else {
// For all other errors, log a critical error with the full stack trace.
$level = Log::CRITICAL;
$message = \sprintf(
'Uncaught Throwable of type %1$s thrown with message "%2$s". Stack trace: %3$s',
\get_class($error),
$error->getMessage(),
$error->getTraceAsString()
);
$category = 'error';
}
// Try to log the error, but don't let the logging cause a fatal error
try {
Log::add($message, $level, $category);
} catch (\Throwable) {
// Logging failed, don't make a stink about it though
}
}
This change transforms the log entries for 404 errors, making them much more appropriate and useful.
Before:
2025-08-03T20:22:33+00:00 CRITICAL ::1 error Uncaught Throwable of type Joomla\CMS\Router\Exception\RouteNotFoundException thrown with message "Page not found". Stack trace: #0 [ROOT]\libraries\src\Application\SiteApplication.php(767): Joomla\CMS\Router\Router->parse(...)
#1 ...
#5 {main}
After:
2025-08-03T20:30:03+00:00 NOTICE ::1 error Page not found (404): https://www.example.com/non-existent-url. Message: "Page not found"
This seems like a valuable improvement for site administrators. I hope this is helpful for consideration.
In my case it works.
Can anyone confirm and review?
Edit:
Added 406 NotAcceptable (wrong API header) Notice.
I work on this issue. Can you please assign this issue to me