Repository: plone/Products.CMFPlone

Issue:
Some Errors cannot render their exceptions during the creation of portal
This is a follow-up for #2203.

A exception of the following type cannot rendered in Plone 5.2:

```
ValueError

Traceback (innermost last):

    Module ZServer.ZPublisher.Publish, line 144, in publish
    Module ZPublisher.mapply, line 85, in mapply
    Module Products.PDBDebugMode.runcall, line 68, in pdb_runcall
    Module ZServer.ZPublisher.Publish, line 44, in call_object
    Module Products.CMFPlone.browser.admin, line 271, in __call__
    Module Products.CMFPlone.factory, line 146, in addPloneSite
    Module Products.GenericSetup.tool, line 388, in runAllImportStepsFromProfile
    __traceback_info__: profile-Products.CMFPlone:plone
    Module Products.GenericSetup.tool, line 1433, in _runImportStepsFromContext
    Module Products.GenericSetup.tool, line 1245, in _doRunImportStep
    __traceback_info__: rolemap
    Module Products.GenericSetup.rolemap, line 102, in importRolemap
    Module <string>, line 8, in manage_permission
    Module AccessControl.requestmethod, line 79, in _curried
    Module OFS.role, line 86, in manage_permission
    Module AccessControl.rolemanager, line 224, in manage_permission

ValueError: The permission <em>Use Database Methods</em> is invalid. 
```

The issue is that the portal and the main_template exist during rendering of ExceptionView but the main_template cannot be rendered because the context of the exception is not the Plone site but the Application. Thus the exception-template cannot be rendered properly. To fix that i suggest we try to render main_template and switch to the basic_template when that fails.


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
@@ -3,7 +3,6 @@
 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
@@ -34,24 +33,16 @@ def __call__(self):
                 'error_type': error_type,
             })
 
-        if getSite() is None:
-            # We cannot get the site, so we cannot render our nice template
-            template = self.basic_template
-        else:
-            # 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)
         request.set('disable_plone.leftcolumn', True)
         request.set('disable_plone.rightcolumn', True)
 
-        return template(
-            error_type=error_type,
-            error_tb=error_tb,
-        )
+        try:
+            return self.index(
+                error_type=error_type,
+                error_tb=error_tb)
+        except:
+            return self.basic_template(
+                error_type=error_type,
+                error_tb=error_tb)


Test patch: