Problem/Motivation

In Drupal\workspaces\Form\WorkspacePublishForm::submitForm we catch \Exception and then output a generic message and indicate that the error has been logged but we are not logging it.

https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/works...

catch (\Exception $e) {
      $this->messenger()->addMessage($this->t('Publication failed. All errors have been logged.'), 'error');
    }

Proposed resolution

We should either allow the exception to be thrown or log it so that it can surface issues.

Issue fork drupal-3376177

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

nlisgo created an issue. See original summary.

nlisgo’s picture

Status: Active » Needs review

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.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs steps to reproduce, +Needs tests

Can you add the exact steps taken to reproduce the error?

Also will need a test case showing the issue.

nlisgo’s picture

The steps I followed to trigger the exception were found in this issue: https://www.drupal.org/project/drupal/issues/3092549

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.

amateescu’s picture

Issue tags: -exception

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.

nlisgo’s picture

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 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.

nlisgo’s picture

Status: Needs work » Needs review

I've added a test. It's quite involved to create the conditions to trigger this exception.

smustgrave’s picture

Status: Needs review » Needs work

CC failure

Also instead of the new parameter (which may need a CR) could we use LoggerTrait?

nlisgo’s picture

Status: Needs work » Needs review

I've addressed the CC failure and also now use LoggerTrait.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

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.

  • lauriii committed 919cebfc on 11.x
    Issue #3376177 by nlisgo, smustgrave, amateescu: Errors on...

  • lauriii committed 08cab321 on 10.1.x
    Issue #3376177 by nlisgo, smustgrave, amateescu: Errors on...
lauriii’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 919cebf and pushed to 11.x. Cherry-picked to 10.1.x as a non-disruptive bug fix. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.