Problem/Motivation
Five builder actions end in a server error instead of a message:
- Pasting or duplicating into a full slot or root:
\OutOfRangeException. - Pasting under a parent that no longer exists:
InvalidNodeException. - Pasting a copied node that no longer exists: the attach is skipped, then the attach event reaches the islands with no node ID, a
TypeError, on a root paste too. - Inserting a preset that no longer exists:
getSources()onNULL. - Inserting a preset into a full root or slot:
\OutOfRangeException.
A pattern preset builder hits two of them every time, since its root takes one node: duplicating the root node, and dropping a preset on the root. Previewing a preset that no longer exists fails like inserting it.
All reproduced in kernel tests. Drag and drop catches the full-target case, ApiActionsController::paste(), ApiController::attachPresetToRoot() and attachPresetToSlot() do not, and nothing catches InvalidNodeException.
Proposed resolution
- One exception subscriber on the
display_builder.api_*routes answersInvalidNodeExceptionand\OutOfRangeExceptionwith the builder's error toast. Catching them in each action would pushApiControllerover its PHPMD complexity limit, which it is one point away from. paste()throwsInvalidNodeExceptionwhen the copied node is gone, instead of dispatching an event about nothing.- A missing preset takes the existing "missing preset data" error path on insert, and a 404 on preview.
Found while reviewing #3624396: Plan: Harden InstanceInterface, IslandInterface and DisplayBuildableInterface as public API before RC1, which makes every instance mutator declare what it throws.
Issue fork display_builder-3626659
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 #2
mogtofu33 commentedComment #4
mogtofu33 commented