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
Comment #3
alexpottDiscussed 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.Comment #4
berdirI guess you actually wanted to do this, then?