Problem/Motivation

Currently, the Entity Presave pipeline is capable of throwing EntityStorageException. EntityStorageBase::doPreSave() can do so itself, although the likelihood is small. However, other presave hook implementations may do so, too, to indicate something failed in the saving process for one reason or another. That exception is currently uncaught, and thus bubbles all the way up to the generic exception handler resulting in a non-descript "The website encountered an unexpected error."

This is a problem in particular for Workbench Moderation, where we need the ability to validate that a state transition can happen, and that validation may, in the case of Workspace module, need to run complex situational logic including database updates. That means this validation cannot be handled by the normal entity validation API, which only introspects the entity state itself and cannot update the database.

See:
#2685179: Add transition validation event
#2683273: Throw exception in WorkbenchModerationSubscriber when no upstream

Proposed resolution

Catch the exception within the Entity API and handle it gracefully; in the case of a form save, that probably means passing a message back up to the form somehow. The system should be able to handle "saving exploded, despite $entity->validate() working", as there's many reasons saving could die.

Remaining tasks

Do it.

User interface changes

Minor to none.

API changes

I think none?

Comments

Crell created an issue. See original summary.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

alexpott’s picture

Discussed with @berdir, @catch, @plach, @xjm, @effulgentsia, @cilefen, @amateescu and @fago. We decided to "won't fix" this issue because we don't support database updates during entity pre-save . If the transition can not be validated during $entity->validate() then we're doing something wrong.

berdir’s picture

Status: Active » Closed (won't fix)

I guess you actually wanted to do this, then?