- Issue created by @andypost
- π¨πSwitzerland berdir Switzerland
ToStringTrait might be tricky, because exceptions and __toString() methods don't like each other, unless that has changed somehow?
- π«π·France andypost
And the suggestion in RFC is to use proper exceptions
Using exceptions instead solves all the above problems, and allows catching the error outside the problematic code path.
If the desired outcome is to terminate the program with no possible way to recover one should use the exit() function with a string argument.
Therefore we propose to deprecate passing E_USER_ERROR to trigger_error()
- π¨πSwitzerland berdir Switzerland
Looks like exception handling in __toString() methods got fixed in PHP 7.4: https://3v4l.org/5ZJ2i. That means we can drop the try/catch and even consider to deprecate that trait? It's only used in two classes in core.
- Status changed to Needs review
3 months ago 3:36pm 5 August 2024 - π«π·France andypost
Yes, just 2 implementations to add, and deprecated, now needs to clean-up
_drupal_error_handler_real()
, maybe better to split out fixes for the remaining usage for scope - π«π·France andypost
@Berdir thank you! it works and the only test needs to be adjusted
Drupal\Tests\Core\StringTranslation\TranslatableMarkupTest::testToString Failed asserting that null matches expected 256. core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php:77
- π«π·France andypost
There's just 4 usages in contrib, so needs to improve message and decide with test, polish CR
- π«π·France andypost
Probably deprecation of
ToStringTrait
better to move to separate issue or it needs second change record - π«π·France andypost
Added to summary why most of time it needs to decide if code needs exception or logging instead of throwing user error as everyone thinks it should be fatal but there's
exit()
or exception re-thrownDrupal does not stop execution for user-level errors, allowing the application to log and continue
- π¬π§United Kingdom catch
I think for 10.4/11.1 we should change all these to E_USER_WARNING and then open follow-ups for each case to consider adding:
1. an assert() so it fails hard during development
2. An exception from 12.x onwards if that's appropriate - π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
kim.pepper β made their first commit to this issueβs fork.
- Merge request !9924[#3465827] Switch E_USER_ERROR to E_USER_WARNING β (Open) created by kim.pepper
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Created an MR for #13
- First commit to issue fork.
- π«π·France andypost
MR!9924 is green now, so it needs follow-up to deprecate
ToStringTrait