I just installed Drupal 9.0 on my local Linux machine, and when I try to install a module (for instance: ctools or token) either using the URL pointing to the tar.gz tarball or by downloading it first to my machine, I get the following error:

/drupal9/core/authorize.php/core/authorize.php?batch=1&id=5&op=do_nojs&op=do
StatusText: OK
ResponseText : Error: Can only throw objects in Drupal\Core\Updater\Updater->install() (line 294 of /var/www/html/drupal9/core/lib/Drupal/Core/Updater/Updater.php).

I don't know what's wrong. I never saw this problem with Drupal 8.

CommentFileSizeAuthor
#3 3150990-3.patch666 bytescburschka

Comments

LpSolit created an issue. See original summary.

cburschka’s picture

Bug introduced a few weeks ago in #2055851: Remove translation of exception messages.

@@ -253,7 +253,7 @@ public function update(&$filetransfer, $overrides = []) {
       return $this->postUpdateTasks();
     }
     catch (FileTransferException $e) {
-      throw new UpdaterFileTransferException(t('File Transfer failed, reason: @reason', ['@reason' => strtr($e->getMessage(), $e->arguments)]));
+      throw new UpdaterFileTransferException("File Transfer failed, reason: '" . strtr($e->getMessage(), $e->arguments) . "'");
     }
   }
 
@@ -291,7 +291,7 @@ public function install(&$filetransfer, $overrides = []) {
       return $this->postInstallTasks();
     }
     catch (FileTransferException $e) {
-      throw new UpdaterFileTransferException(t('File Transfer failed, reason: @reason', ['@reason' => strtr($e->getMessage(), $e->arguments)]));
+      throw new UpdaterFileTransferException("File Transfer failed, reason: '" . strtr($e->getMessage(), $e->arguments)) . "'";
     }
   }

The first of these changes is correct. The second is parenthesized incorrectly. The result is that the exception is concatenated with a string, therefore converted to a string, which then cannot be thrown.

cburschka’s picture

Status: Active » Needs review
StatusFileSize
new666 bytes

Trivial fix.

But I'm concerned that this slipped through. (1) Static code inspection in IDE marks it as an error, which means our automated code analysis is not thorough enough. (2) Evidently this code path isn't covered by tests either.

cburschka’s picture

Title: Installing a module fails » Updater::install() crashes on file transfer exceptions.
krzysztof domański’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +Needs followup

We should add a follow-up for the missing test coverage but going to commit this since it was introduced.

Committed and pushed 8596983c00 to 9.1.x and 806618e681 to 9.0.x and f323884b0b to 8.9.x. Thanks!

  • alexpott committed 8596983 on 9.1.x
    Issue #3150990 by cburschka: Updater::install() crashes on file transfer...

  • alexpott committed 806618e on 9.0.x
    Issue #3150990 by cburschka: Updater::install() crashes on file transfer...

  • alexpott committed f323884 on 8.9.x
    Issue #3150990 by cburschka: Updater::install() crashes on file transfer...
xjm’s picture

Status: Fixed » Needs work

Hotfix commit makes sense but let's leave it open to ensure the tests issue gets filed. Thanks!

cburschka’s picture

A unit test of the Drupal\Core\Updater\Updater class could probably cover most of this (using vfsStreamWrapper to simulate file operations).

Beside that, I wonder if there are ways we could get phpstan or codesniffer to check for type errors like this? Throwing an expression that isn't an object or an instance of throwable should have been flagged by the automated checks...

alexpott’s picture

@cburschka can you create the follow-up issue to discuss this - then we can close this one.

Cheers!

cburschka’s picture

Created #3151319: Test coverage for \Drupal\Core\Updater classes for the unit tests.

I don't know enough of the status of phpstan in DrupalCI to know if we need an issue for that or if it is something that is in already in progress...

alexpott’s picture

Status: Needs work » Fixed
Issue tags: -Needs followup

@cburschka thanks - now we have the followup we can close this one.

Status: Fixed » Closed (fixed)

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