Problem/Motivation

Let's get rid of ! for exception messages.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

dawehner created an issue. See original summary.

dawehner’s picture

Assigned: dawehner » Unassigned
Status: Active » Needs review
StatusFileSize
new4.6 KB

There we go.

Status: Needs review » Needs work

The last submitted patch, 2: 2568775-2.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new6.56 KB
new1.95 KB

Fixed the failures.

The last submitted patch, 2: 2568775-2.patch, failed testing.

xjm’s picture

Issue tags: +Needs manual testing
  1. +++ b/core/modules/config/src/Tests/ConfigImporterTest.php
    @@ -295,7 +295,7 @@ function testSecondaryWriteSecondaryFirst() {
    -    $this->assertEqual($logs[0], SafeMarkup::format("Unexpected error during import with operation @op for @name: 'config_test' entity with ID '@name_secondary' already exists.", array('@op' => 'create', '@name' => $name_primary, '@name_secondary' => 'secondary')));
    +    $this->assertEqual($logs[0], SafeMarkup::format("Unexpected error during import with operation @op for @name: @message", array('@op' => 'create', '@name' => $name_primary, '@message' => "'config_test' entity with ID 'secondary' already exists.")));
    

    Hm hard to read. Could we just kill the SafeMarkup::format() and just assert the string?

  2. +++ b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php
    @@ -72,7 +73,7 @@ public function testImportWithFailingRewind() {
    -      ->with("Migration failed with source plugin exception: $exception_message");
    +      ->with("Migration failed with source plugin exception: " . Html::escape($exception_message));
    

    Hmm. This gets at what I was concerned about with these -- what escaping is correct for all of these messages? Are we introducing malformatted messages where some markup is escaped twice, or what did this look like in HEAD?

dawehner’s picture

StatusFileSize
new6.7 KB
new1.08 KB

Hm hard to read. Could we just kill the SafeMarkup::format() and just assert the string?

I think we should, it makes things easier to read!

Hmm. This gets at what I was concerned about with these -- what escaping is correct for all of these messages? Are we introducing malformatted messages where some markup is escaped twice, or what did this look like in HEAD?

Well, IMHO those exceptions should be in english without using t() or anything escaping related in the first place, see our usage to just concat everything together for exception messages.

Good luck with figuring out how to cause those exceptions in migrate.

dawehner’s picture

Hmm. This gets at what I was concerned about with these -- what escaping is correct for all of these messages? Are we introducing malformatted messages where some markup is escaped twice, or what did this look like in HEAD?

Well, its tricky because those messages are supposed to be used both in CLI and the Drupal UI (for some potential future but IMHO not so helpful migrate UI), so we need the proper HTML escaping strategy.

Some manual testing:

  • Opened MigrateExecuteable and looked for the place where we wrap an exception:
  • Alright, the source plugin needs to throw an exception
  • Sadly not a single one actually throws one (went to source/d6 and into the SQL and Drupal plugins)
  • Alright, let's simulate what could happen:
    
    try {
      throw new \Exception(t('müh'));
    }
    catch (\Exception $e) {
      drush_print_r(t('Muh @meh', ['@meh' => $e->getMessage()]));
    }
    
    try {
      throw new \Exception("' this are quotes'");
    }
    catch (\Exception $e) {
      drush_print_r(t('Muh @meh', ['@meh' => $e->getMessage()]));
    }
    
    try {
      throw new \Exception(t('Foo bar %meh', ['%meh' => 'Ha']));
    }
    catch (\Exception $e) {
      drush_print_r(t('Muh @meh', ['@meh' => $e->getMessage()]));
    }
    
    Muh müh
    Muh ' this are quotes'
    Muh Foo bar <em class="placeholder">Ha</em>
    

Let's see whether this was enough manual testing.

alexpott’s picture

alexpott’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/Updater/Updater.php
    @@ -257,7 +257,7 @@ public function update(&$filetransfer, $overrides = array()) {
    -      throw new UpdaterFileTransferException(t('File Transfer failed, reason: !reason', array('!reason' => strtr($e->getMessage(), $e->arguments))));
    +      throw new UpdaterFileTransferException(t('File Transfer failed, reason: @reason', array('@reason' => strtr($e->getMessage(), $e->arguments))));
    
    @@ -295,7 +295,7 @@ public function install(&$filetransfer, $overrides = array()) {
    -      throw new UpdaterFileTransferException(t('File Transfer failed, reason: !reason', array('!reason' => strtr($e->getMessage(), $e->arguments))));
    +      throw new UpdaterFileTransferException(t('File Transfer failed, reason: @reason', array('@reason' => strtr($e->getMessage(), $e->arguments))));
    

    We shouldn't be using t() here - also as this is never caught the correct thing to do here is to remove t completely. And join the strings together.

  2. +++ b/core/modules/config/src/Tests/ConfigImporterTest.php
    @@ -295,7 +296,7 @@ function testSecondaryWriteSecondaryFirst() {
    +    $this->assertEqual($logs[0], "Unexpected error during import with operation create for $name_primary: " . Html::escape("'config_test' entity with ID 'secondary' already exists."));
    

    Let's just call Html::escape on the entire string.

dawehner’s picture

Status: Needs work » Needs review
Issue tags: -Needs manual testing
StatusFileSize
new6.7 KB
new809 bytes

We shouldn't be using t() here - also as this is never caught the correct thing to do here is to remove t completely. And join the strings together.

Well, the problem is that those messages are displayed for the user, do we want to deal with that?

Let's just call Html::escape on the entire string.

Sure.

alexpott’s picture

+++ b/core/lib/Drupal/Core/Updater/Updater.php
@@ -257,7 +257,7 @@ public function update(&$filetransfer, $overrides = array()) {
-      throw new UpdaterFileTransferException(t('File Transfer failed, reason: !reason', array('!reason' => strtr($e->getMessage(), $e->arguments))));
+      throw new UpdaterFileTransferException(t('File Transfer failed, reason: @reason', array('@reason' => strtr($e->getMessage(), $e->arguments))));

@@ -295,7 +295,7 @@ public function install(&$filetransfer, $overrides = array()) {
-      throw new UpdaterFileTransferException(t('File Transfer failed, reason: !reason', array('!reason' => strtr($e->getMessage(), $e->arguments))));
+      throw new UpdaterFileTransferException(t('File Transfer failed, reason: @reason', array('@reason' => strtr($e->getMessage(), $e->arguments))));

Ah I see...

  catch (UpdaterException $e) {
    _update_batch_create_message($context['results']['log'][$project], t('Error installing / updating'), FALSE);
    _update_batch_create_message($context['results']['log'][$project], $e->getMessage(), FALSE);
    $context['results']['log'][$project]['#abort'] = TRUE;
    return;
  }

Wow there is some ugly code here...

            $message = t($e->getMessage(), $e->arguments);
            $throw_message = t('Unable to create %directory due to the following: %reason', array('%directory' => $directory, '%reason' => $message));
            throw new UpdaterException($throw_message);

So imho we should create a specific exception for each message and catch in the batch process and have the translations done their. This exception communication pattern is not nice.

dawehner’s picture

Well, I tried staring with that, but then I realized we would have not only fix the exception messages in Updater, but also FileTransfer which has file transfer specific exceptions,
like "NO FTP backend available" ... so yeah in other words these messages are currently not translatable.

alexpott’s picture

Priority: Major » Critical

This is part of the critical meta.

lauriii’s picture

StatusFileSize
new12.53 KB
new8.77 KB

No idea if this is gonna fly..

dawehner’s picture

I doubt that getting rid of the try catch will help at all. can you clarify what you had in mind with that change?

Status: Needs review » Needs work

The last submitted patch, 15: replace_remaining-2568775-15.patch, failed testing.

lauriii’s picture

Assigned: Unassigned » lauriii

So idea I had in my mind was to get rid of multiple level of exceptions. I'll keep working on this one.

dawehner’s picture

I still don't get that why we need to solve that to solve the critical part of the issue. You can improve things for ages. Imho we need tests for that stuff instead to not loose safety in the first place.

lauriii’s picture

Status: Needs work » Needs review
StatusFileSize
new15.94 KB
new4.31 KB

Created UpdaterFileTransferFolderException for the case where folder creating fails. I also ensured that thaa Updater::update() is not being used anywhere else than in the update_authorize_batch_copy_project().

lauriii’s picture

Assigned: lauriii » Unassigned

Status: Needs review » Needs work

The last submitted patch, 21: replace_remaining-2568775-20.patch, failed testing.

lauriii’s picture

lauriii’s picture

Status: Needs work » Needs review
dawehner’s picture

Well, the reason for the try {} catch {} in \Drupal\Core\Updater\Updater::update is because the transfer mechanism might throw an exception,
and we simply can't and shouldn't know which one exist.

joelpittet’s picture

Let's move the exception moving around to a follow, this is getting out of scope to help unblock the !placeholder removal.

While it is a good suggestion to deal with separating translations from exception messages, the scope of changes needed it deserves it's own issue.

joelpittet’s picture

Status: Needs review » Needs work

I've tried to boil off the conversation into the follow-up here:
#2571565: Installer and Upgrade specific Exceptions caught for translated messages.

@lauriii please post your solution over there for the try/catch and specific message catching.

This one needs to be re-posted back to #11 with any other changes needed since then.

alexpott’s picture

I agree with #29 - and sorry it's my fault that the scope expanded, it is a shame that the fix is not simple but I definitely think it worth reducing scope here to get the !placeholder removal done.

lauriii’s picture

Assigned: Unassigned » lauriii

Working on this

lauriii’s picture

Assigned: lauriii » Unassigned
Status: Needs work » Needs review
StatusFileSize
new6.7 KB

I'm just re-uploading the patch from #11.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Checked to see if I could find any more by grepping around for ag -C 2 getMessage

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed ab01a83 and pushed to 8.0.x. Thanks!

  • alexpott committed c159655 on 8.0.x
    Issue #2568775 by dawehner, lauriii, alexpott, joelpittet, xjm: Replace...

Status: Fixed » Closed (fixed)

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