Drupal core's coding standards forbid translated exceptions, but does that anyway β€” f.e. FileValidationException

Created on 2 February 2023, almost 2 years ago
Updated 14 February 2023, almost 2 years ago

Problem/Motivation

Discovered at #3325654-32: Improve the user experience of having your staged update deleted before it was applied β†’ .

Well well well, πŸ› phpcs stopped working since the switch to testing on Drupal 10.0.x by default Fixed is already striking:

----------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
----------------------------------------------------------------------
 699 | WARNING | Exceptions should not be translated
     |         | (DrupalPractice.General.ExceptionT.ExceptionT)
 704 | WARNING | Exceptions should not be translated
     |         | (DrupalPractice.General.ExceptionT.ExceptionT)
 712 | WARNING | Exceptions should not be translated
     |         | (DrupalPractice.General.ExceptionT.ExceptionT)
----------------------------------------------------------------------

… and it's wrong, because \Drupal\automatic_updates\Form\UpdateReady::buildForm() will catch this and present it to the end user:

  public function buildForm(array $form, FormStateInterface $form_state, string $stage_id = NULL) {
    try {
      $this->updater->claim($stage_id);
    }
    catch (StageOwnershipException $e) {
      $this->messenger()->addError($e->getMessage());
      return $form;
    }
…

… but of course, we do have to comply with Drupal core's phpcs rules.

Not sure how to proceed here. It seems that "exceptions for user-facing strings (that should be translated)" is a bad practice, but this module has embraced that. It's technically out of scope to fix here though.

So … worked around it, and tagging .

Steps to reproduce

Proposed resolution

TBD

Remaining tasks

TBD

User interface changes

None.

API changes

TBD

Data model changes

TBD

πŸ“Œ Task
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024