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() on NULL.
  • 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 answers InvalidNodeException and \OutOfRangeException with the builder's error toast. Catching them in each action would push ApiController over its PHPMD complexity limit, which it is one point away from.
  • paste() throws InvalidNodeException when 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.

Command icon 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

mogtofu33 created an issue. See original summary.

mogtofu33’s picture

Title: Paste, duplicate and preset insert end in a server error when the target is full or gone » Paste, duplicate and preset insert end in a server error when the target is full or gone

mogtofu33’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • mogtofu33 committed fc628275 on 1.0.x
    fix: #3626659 Paste and preset insert refuse a full or missing target...