Problem/Motivation
Following the release of #3281936, any patternkit blocks with invalid data cause a white screen of death (WSOD) error. This prevents access to most configuration of the blocks and makes the issue very hard to debug. Aside from that, it's definitely not the desirable behavior for a production environment if an exception happens while trying to render a pattern.
Instead, the block should contain the exception to its own scope and allow the rest of the page to render. Ideally, information about the error would also be available to the developer to assist in debugging and resolution.
Steps to reproduce
The process of creating an invalid block is a bit convoluted, but it may be encountered in situations where a block already existed using a pattern and the pattern changed, or a pattern is being actively developed and adjusted.
- Edit the layout of a node with Layout Builder enabled
- Place a new pattern block with valid content configured
- Save the node
- In the database, alter the stored JSON data in the `patternkit_field_data` table contained in the `data` column
- Assuming the altered data doesn't validate against the pattern schema, you should see a white screen error
Proposed resolution
To fix this, error-handling throughout the rendering process needs to be improved and captured at the pattern rendering level to prevent it from breaking the entire page.
- Add handling for data validation errors
- Capture the errors at the pattern render element level
- Render a load failure message instead
Additional wins along the way could include:
- Expose the exception error message for debugging
- Support the ability to override errored pattern renders for per-site customization if desired
User interface changes
- Pattern blocks that fail to render will now show a failure message in place of the rendered pattern.
- Logged error messages for pattern render failures now include the exception message and data being rendered.
API changes
- Schema instances using the underlying Swaggest/JSON-Schema library may now be created using the JSON string and the new public service: patternkit.schema.schema_factory
- Validation errors during the schema traversal process will now throw as a \Drupal\patternkit\Exception\SchemaValidationException
- A new PatternError render element has been introduced that handles display of patterns that fail to render.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | patternkit-3293860--pattern-error-element--4.patch | 44.38 KB | slucero |
Issue fork patternkit-3293860
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
sluceroI've added some browser tests to confirm the placement and rendering of blocks through the UI as well as verifying the rendering of the new pattern_error element. With that in place, I've opened the MR for review.
I'm also attaching a patch for easier testing of this functionality. To use it, include the following snippet within the patches section of your project's composer.json file:
Comment #4
sluceroAttaching a reroll of the patch with latest changes included for easy testing.
To use with a Composer patch workflow, add the following to your composer.json file:
Comment #6
sluceroMerged for inclusion in the Beta 4 release!