Having a strange issue - devMode is set to false, if I go to /404, I get the custom 404 page, which is great.

If I go to /something1234567890 (which is definitely not an entry's URL) I get the following exception:

yii\web\NotFoundHttpException: Template not found: something1234567890

I have tried adding debugging to my base templates but it looks like it is not getting as far as them.

Does anyone have an idea where I can start trying to debug this?

Stack trace:

2018-09-17 00:36:15 [xxx.xxx.xx.x][-][xxxxxxxxxxxxxxxxx][trace][yii\web\Application::handleRequest] Route requested: 'templates/render'
2018-09-17 00:36:15 [xxx.xxx.xx.x][-][xxxxxxxxxxxxxxxxx][trace][yii\base\Controller::runAction] Route to run: templates/render
2018-09-17 00:36:15 [xxx.xxx.xx.x][-][xxxxxxxxxxxxxxxxx][trace][yii\base\InlineAction::runWithParams] Running action: craft\controllers\TemplatesController::actionRender()
2018-09-17 00:36:15 [xxx.xxx.xx.x][-][xxxxxxxxxxxxxxxxx][trace][nystudio107\seomatic\{closure}] ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION
2018-09-17 00:36:15 [xxx.xxx.xx.x][-][xxxxxxxxxxxxxxxxx][error][yii\web\HttpException:404] yii\web\NotFoundHttpException: Template not found: something1234567890 in /home/vagrant/code/craft-site/vendor/craftcms/cms/src/controllers/TemplatesController.php:70
2018-09-17 00:36:15 [xxx.xxx.xx.x][-][xxxxxxxxxxxxxxxxx][error][yii\web\HttpException:404] yii\web\NotFoundHttpException: Template not found: something1234567890 in /home/vagrant/code/craft-site/vendor/craftcms/cms/src/controllers/TemplatesController.php:70
Stack trace:
#0 [internal function]: craft\controllers\TemplatesController->actionRender('something123456...', Array)
#1 /home/vagrant/code/craft-site/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#2 /home/vagrant/code/craft-site/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#3 /home/vagrant/code/craft-site/vendor/craftcms/cms/src/web/Controller.php(103): yii\base\Controller->runAction('render', Array)
#4 /home/vagrant/code/craft-site/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('render', Array)
#5 /home/vagrant/code/craft-site/vendor/craftcms/cms/src/web/Application.php(282): yii\base\Module->runAction('templates/rende...', Array)
#6 /home/vagrant/code/craft-site/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('templates/rende...', Array)
#7 /home/vagrant/code/craft-site/vendor/craftcms/cms/src/web/Application.php(271): yii\web\Application->handleRequest(Object(craft\web\Request))
#8 /home/vagrant/code/craft-site/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#9 /home/vagrant/code/craft-site/public/index.php(22): yii\base\Application->run()
#10 {ma    in}

Update 1

The devMode toggling works on another Craft 3 site I have, just not this particular one. Maybe it is a database issue?

Update 2

I have tried this codebase with a fresh database and still getting the same error, so it must be something to do with my codebase?


Craft will serve one of 3 types of 404 errors.

When Dev Mode is enabled, you will get something like this, which shows the full stack trace leading up to the NotFoundHttpException:

enter image description here

If this looks like what you’re getting, then Dev Mode is definitely enabled. Double-check config/general.php for devMode, or web/index.php for YII_DEBUG.

Otherwise, you will get something like this in Craft’s Control Panel (as well as the front end if you haven’t specified a 404 template yet):

enter image description here

If it’s a front-end request, and you have a 404 template, then Craft will render your 404 template. If it encounters an error when trying to do that, a plain text error will be displayed, with no styling.

| improve this answer | |
  • devMode is set to false in config/general.php I swear! Is there any way to get Craft to dump what this value is before rendering the error to verify? – Mike F Sep 19 '18 at 12:45
  • @MikeF Try going into your Control Panel - do you see the stripes in the top-left that indicate that Dev Mode is enabled? – Brandon Kelly Sep 19 '18 at 12:55
  • Nothing there, still getting the same errors :( – Mike F Sep 19 '18 at 13:00
  • OK, can you send a database backup, your composer.json, composer.lock, and config & template files over to support@craftcms.com, and tell us which URL you're getting this on? We can try reproducing it with those. – Brandon Kelly Sep 19 '18 at 13:07

There's a long discussion of all of this in the Handling Errors Gracefully in Craft CMS article, if it helps.

| improve this answer | |
  • Thanks for the reply - had a look through the article and I'm afraid the actionRenderError() is not being called. As you can see from my stack trace it's the actionRender() method I am stuck inside, and not being able to handle the NotFoundHttpException thrown inside there – Mike F Sep 19 '18 at 8:13

Take a look in your general.php config file and see if you're overwriting the errorTemplatePrefix setting. It might look something like:

'errorTemplatePrefix' => "_errors/"

So you might need to move the 404.html file into "/templates/_errors/" directory.

See docs v3

| improve this answer | |
  • Thanks for your answer - errorTemplatePrefix isn't being overridden in config/general.php though. – Mike F Sep 18 '18 at 14:02
  • Also this is v3 btw – Mike F Sep 18 '18 at 16:08
  • 1
    Just updated the link to v3 doc. I'd suggest making sure that Craft is definitely not running Devmode and to add the config in my answer a go and see if that makes a difference. Prefixing 404.html with a "_" or putting the 404.html in a "_errors/" directory follows best practice so the file can't be loaded when going to "exmaple.com/404.html" as this would result in returning a 200 response instead of 404. – Jamie Jenkins Sep 19 '18 at 9:13
  • Have tried as you have suggested and no luck unfortunately. I have updated my question to include that I've got another, smaller Craft site where I have no errorTemplatePrefix config and the file templates/404.html, and the devMode toggle works as expected in the docs. I am starting to think it must be something in the database which is the issue? – Mike F Sep 19 '18 at 9:20
  • Okay, I haven't seen a DB issue result in this kind of thing before but you never know. Are these two Craft sites running the same version? Also If there's not too many plugins on the site you could try disabling them on by one and see if that has any effect. – Jamie Jenkins Sep 19 '18 at 9:24

If you've set devMode to false in your local environment and you still can't see your 404 template, go to your own user account in the CMS and uncheck "Show full exception views when Dev Mode is disabled".

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.