-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat: add placeholder-level error handling #8118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add placeholder-level error handling #8118
Conversation
Reviewer's Guide by SourceryThis pull request refactors error handling when rendering placeholders. It introduces a try-except block to catch exceptions during plugin rendering and template rendering, and logs the error. It also adds a visual representation of the error in the CMS when in edit mode. Sequence diagram for placeholder error handling flowsequenceDiagram
participant CMS as CMS System
participant Renderer as ContentRenderer
participant Plugin as Plugin Instance
participant Template as Template Engine
participant Logger as Error Logger
CMS->>Renderer: render_placeholder()
activate Renderer
Renderer->>Plugin: render_plugin()
activate Plugin
alt Successful rendering
Plugin-->>Renderer: rendered content
else Exception occurs
Plugin-->>Renderer: throws exception
Renderer->>Logger: log error
alt Edit mode active
Renderer-->>CMS: error visualization
else Production mode
alt CATCH_PLUGIN_500_EXCEPTION enabled
Renderer-->>CMS: empty content
else
Renderer-->>CMS: re-raise exception
end
end
end
deactivate Plugin
deactivate Renderer
Class diagram for renderer error handlingclassDiagram
class BaseRenderer {
+render_placeholder()
+render_plugin()
}
class ContentRenderer {
+render_exception(action, context, placeholder, editable)
+render_placeholder()
+render_plugin()
}
class StructureRenderer {
+render_placeholder()
+render_plugin()
}
class LegacyRenderer {
+render_placeholder()
+get_editable_placeholder_context()
}
BaseRenderer <|-- ContentRenderer
BaseRenderer <|-- StructureRenderer
ContentRenderer <|-- LegacyRenderer
note for ContentRenderer "New error handling logic"
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
@florianschieder Please comment. |
Looks good on a first glance 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Let's get this merged.
@fsbraun Looks great! Thank you very much for the helpful solution! |
Description
fixes #7974
Since django CMS 4, exceptions that happen during plugin rendering have been caught and displayed a message at the plugin's position.
After feedback from the community, this PR refactors error handling when rendering placeholders.
.
Exceptions are now caught on placeholder level.
In edit mode, a message about the exception is shown for the placeholder. If
settings.DEBUG == True
this message includes the full Django trace.Editors still can edit plugins causing the exception. It can be edited by double-clicking the error message or through the structure board.
In preview mode and on site, the placeholder containing the plugin will render empty.
If
settings.CMS_CATCH_PLUGIN_500_EXCEPTION
is set toFalse
, trying to view content that raises an exception will trigger a server error (http 500). Preview and edit modes will still work.Screenshot
This is a full error message in edit mode and with
DEBUG = True
. The plugin with pk 35 caused a division by zero exception. It can be edited by double-clicking the red error message. Toolbar and structure board are available.The same warning message on a production system is shorter:

Related resources
Checklist
develop-4
Summary by Sourcery
Bug Fixes: