Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Some times we forget to catch the exceptions generated by the wrap()
and wrapMultiple
methods. I have come to think that this was a bad pattern since it lead to a poor DX.
API changes
Let's return NULL
when the entity cannot be wrapped instead of throwing an exception.
This will require a major version bump since the public interface will change. We will also need to add a change record to it.
Comment | File | Size | Author |
---|---|---|---|
#12 | 3181885--graceful-error--11.patch | 9.88 KB | e0ipso |
#7 | 3181885-implement-a-graceful--7.patch | 24.29 KB | e0ipso |
Comments
Comment #2
e0ipsoFirst pass, let's see what the testbot thinks.
Comment #4
e0ipsoLet's see how we can test those PHP errors.
Comment #5
e0ipsoComment #7
e0ipsoOooops, some other code was in the way.
This should work now.
Comment #8
e0ipsoComment #9
e0ipsoComment #10
e0ipsoOn second thought, we might want to drop the
trigger_error
to stop spamming the logs.There is a legit use case to try to wrap an entity that has no repository.
In this case we want node types that have no associated wrapper to return access neutral. In 3.x the code should look like:
Comment #11
e0ipsoComment #12
e0ipsoThis drops the trigger_error and beautifies the code.
Comment #13
e0ipsoComment #14
e0ipsoMerging and fixing the change record.