Repository: plone/Products.CMFPlone

Issue:
Error message broken on Zope-Root
http://localhost:8080/foo when `foo` does not exists (i.e. is not a Plone instance) results in a traceback.

In Plone 5.1 we used to get:
```
<h2>Site Error</h2> <p>An error was encountered while publishing this resource. </p> <p><strong>Resource not found</strong></p> Sorry, the requested resource does not exist.<p>Check the URL and try again.</p><p><b>Resource:</b> foo GET</p> <hr noshade="noshade"/> <p>Troubleshooting Suggestions</p> <ul> <li>The URL may be incorrect.</li> <li>The parameters passed to this resource may be incorrect.</li> <li>A resource that this resource relies on may be encountering an error.</li> </ul> <p>For more detailed information about the error, please refer to the error log. </p> <p>If the error persists please contact the site maintainer. Thank you for your patience. </p> 
```
That was ugly (escaped html) but the text was correct.

Plone 5.2 on the other hand tries to render the `ExceptionView` and fails sind the app has no method `Language()`. 

```
Traceback (innermost last):

    Module ZServer.ZPublisher.Publish, line 261, in publish_module_standard
    Module Products.PDBDebugMode.runcall, line 83, in pdb_publish
    Module ZServer.ZPublisher.Publish, line 182, in publish
    Module ZServer.ZPublisher.exceptionhook, line 117, in __call__
    Module Products.CMFPlone.browser.exceptions, line 49, in __call__
    Module Products.Five.browser.pagetemplatefile, line 125, in __call__
    Module Products.Five.browser.pagetemplatefile, line 60, in __call__
    Module zope.pagetemplate.pagetemplate, line 134, in pt_render
    Module Products.PageTemplates.engine, line 85, in __call__
    Module z3c.pt.pagetemplate, line 163, in render
    Module chameleon.zpt.template, line 261, in render
    Module chameleon.template, line 191, in render
    Module chameleon.template, line 171, in render
    Module 4195113b17720aee65cd4ca2a7e7ba2d.py, line 1095, in render
    Module 9fafff3b78c7ea63dcd15308ddf75fb8.py, line 652, in render_master
    Module Products.PageTemplates.expression, line 105, in __call__
    Module plone.app.layout.globals.portal, line 80, in language

AttributeError: 'RequestContainer' object has no attribute 'Language'

 - Expression: "portal_state/language"
 - Filename: ... one/Products/CMFPlone/browser/templates/main_template.pt
 - Location: (line 12: col 11)
 - Source: lang portal_state/language; 

 ^^^^^^^^^^^^^^^^^^^^^

 - Arguments: 
    repeat: {...} (0) 
    template: <ViewPageTemplateFile - at 0x10da74950> 
    views: <ViewMapper - at 0x10e47d9d0> 
    modules: <_SecureModuleImporter - at 0x10867bed0> 
    args: <tuple - at 0x1066a0050> 
    here: <ImplicitAcquisitionWrapper at 0x10d34b960> 
    user: <SpecialUser - at 0x108457290> 
    nothing: <NoneType - at 0x1065eeeb8> 
    container: <ImplicitAcquisitionWrapper at 0x10d34b960> 
    request: <HTTPRequest - at 0x10e5f1c90> 
    wrapped_repeat: <SafeMapping - at 0x10c50a5f0> 
    traverse_subpath: <list - at 0x10e88d488> 
    default: <object - at 0x1066f6ba0> 
    loop: {...} (0) context: <ImplicitAcquisitionWrapper at 0x10d34b960> 
    view: <SimpleViewClass from /Users/pbauer/workspace/coredev/src/Products.CMFPlone/Products/CMFPlone/browser/templates/error_message.pt index.html at 0x10c45f9d0> 
    translate: <function translate at 0x10e59f050> 
    root: <ImplicitAcquisitionWrapper at 0x10d34b960> 
    options: {...} (2) 
    target_language: <NoneType - at 0x1065eeeb8>
```


Discussion:

Resolving patch:
diff --git a/Products/CMFPlone/browser/exceptions.py b/Products/CMFPlone/browser/exceptions.py
--- a/Products/CMFPlone/browser/exceptions.py
+++ b/Products/CMFPlone/browser/exceptions.py
@@ -1,7 +1,10 @@
+# -*- coding: utf-8 -*-
 from AccessControl import getSecurityManager
 from Products.Five import BrowserView
 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
 from zExceptions.ExceptionFormatter import format_exception
+from zope.component.hooks import getSite
+
 import json
 import sys
 
@@ -31,13 +34,17 @@ def __call__(self):
                 'error_type': error_type,
             })
 
-        # Use a simplified template if main_template is not available
-        try:
-            self.context.unrestrictedTraverse('main_template')
-        except:
+        if getSite() is None:
+            # We cannot get the site, so we cannot render our nice template
             template = self.basic_template
         else:
-            template = self.index
+            # Use a simplified template if main_template is not available
+            try:
+                self.context.unrestrictedTraverse('main_template')
+            except:
+                template = self.basic_template
+            else:
+                template = self.index
 
         # Render page with user-facing error notice
         request.set('disable_border', True)


Test patch: