- Issue created by @nlisgo
47:19 44:38 Running- @nlisgo opened merge request.
- Status changed to Needs review
over 1 year ago 1:11pm 22 July 2023 - 🇬🇧United Kingdom nlisgo
The fix I am proposing is that we should not try to catch
\Exception
. This is the easiest way to ensure the unexpected error is triggered and logged.If it is thrown then an issue should be created.
- Status changed to Needs work
over 1 year ago 9:32pm 22 July 2023 - 🇺🇸United States smustgrave
Can you add the exact steps taken to reproduce the error?
Also will need a test case showing the issue.
- 🇬🇧United Kingdom nlisgo
The steps I followed to trigger the exception were found in this issue: https://www.drupal.org/project/drupal/issues/3092549 🐛 Custom blocks with media are not being displayed Active
The fix for that issue is independent of this related issue because the problem with this code is that unexpected exceptions are being completely overlooked. I could force an error to trigger the exception in a unit test but I'm not sure what value that would add?
There is no justification for the catch all of \Exception and it clearly isn't logging as is stated in the message that I'm removing in the MR.
I will attempt to add a test next week.
- 🇷🇴Romania amateescu
The justification for catching all exceptions there is that content editors usually can't do anything to fix them, so the idea was to fail gracefully. Not logging the exception is a problem though, so we should use
\Drupal\Core\Utility\Error::logException()
there. - last update
over 1 year ago 29,879 pass - 🇬🇧United Kingdom nlisgo
The justification for catching all exceptions there is that content editors usually can't do anything to fix them, so the idea was to fail gracefully. Not logging the exception is a problem though, so we should use \Drupal\Core\Utility\Error::logException() there.
Respectfully, I'm going to suggest that this issue does not require steps to recreate or a test. Not trying to be difficult but a caught exception that discards the exception and isn't logged as expected is steps to recreate enough?
The issue https://www.drupal.org/project/drupal/issues/3092549 🐛 Custom blocks with media are not being displayed Active drew my attention to this issue. I needed to refactor this code to surface the error.
I will persist with adding a test but the test I'm tempted to add will not be related to any known issue. I will just trigger a random exception and then confirm that it is logged.
Removing tag to add steps to reproduce.
- last update
over 1 year ago 29,881 pass - last update
over 1 year ago 29,886 pass - last update
over 1 year ago 29,886 pass - last update
over 1 year ago Custom Commands Failed - Status changed to Needs review
over 1 year ago 5:21pm 28 July 2023 - 🇬🇧United Kingdom nlisgo
I've added a test. It's quite involved to create the conditions to trigger this exception.
- last update
over 1 year ago Custom Commands Failed - Status changed to Needs work
over 1 year ago 9:52pm 30 July 2023 - 🇺🇸United States smustgrave
CC failure
Also instead of the new parameter (which may need a CR) could we use LoggerTrait?
- last update
over 1 year ago 29,909 pass - Status changed to Needs review
over 1 year ago 11:18pm 30 July 2023 - 🇬🇧United Kingdom nlisgo
I've addressed the CC failure and also now use LoggerTrait.
- Status changed to RTBC
over 1 year ago 10:10am 31 July 2023 - 🇷🇴Romania amateescu
I checked why we were saying that errors were logged in the form but not actually logging them and the reason is that we're doing it in the workspace publisher: https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/works...
However, there are a few things happening before and after that try/catch where an exception can be thrown, so the patch from this issue is correct, we also need to log errors in the form.
- Status changed to Fixed
over 1 year ago 10:30am 31 July 2023 Automatically closed - issue fixed for 2 weeks with no activity.