PoStreamReader::readLine() throws an error on module install

Created on 2 August 2022, almost 2 years ago
Updated 20 March 2024, 3 months ago

Problem/Motivation

I've downaloaded a new module and want to enable it, but get fatal error. I've tried to enable several different modules and every time get this error:

$ drush en honeypot 
>  [notice] Checked fr translation for honeypot.
>  [notice] Checked nl translation for honeypot.
>  [error]  The specified file 'temporary://fileie34b1' could not be copied because the destination directory 'translations://' is not properly configured. This may be caused by a problem with file or directory permissions. 
>  [error]  Unable to download translation file https://ftp.drupal.org/files/translations/all/honeypot/honeypot-2.1.1.fr.po. 
>  [warning] fopen(translations://honeypot-2.1.1.fr.po): Failed to open stream: "Drupal\locale\StreamWrapper\TranslationsStream::stream_open" call failed PoStreamReader.php:154
>  [error]  TypeError: fgets(): Argument #1 ($stream) must be of type resource, bool given in fgets() (line 248 of /app/docroot/core/lib/Drupal/Component/Gettext/PoStreamReader.php) #0 /app/docroot/core/lib/Drupal/Component/Gettext/PoStreamReader.php(248): fgets(false)
> #1 /app/docroot/core/lib/Drupal/Component/Gettext/PoStreamReader.php(186): Drupal\Component\Gettext\PoStreamReader->readLine()
> #2 /app/docroot/core/lib/Drupal/Component/Gettext/PoStreamReader.php(217): Drupal\Component\Gettext\PoStreamReader->readItem()
> #3 /app/docroot/core/lib/Drupal/Component/Gettext/PoStreamReader.php(155): Drupal\Component\Gettext\PoStreamReader->readHeader()
> #4 /app/docroot/core/modules/locale/src/Gettext.php(56): Drupal\Component\Gettext\PoStreamReader->open()
> #5 /app/docroot/core/modules/locale/locale.bulk.inc(213): Drupal\locale\Gettext::fileToDatabase(Object(stdClass), Array)
> #6 /app/docroot/core/modules/locale/locale.batch.inc(191): locale_translate_batch_import(Object(stdClass), Array, Object(DrushBatchContext))
> #7 /app/vendor/drush/drush/includes/batch.inc(261): locale_translation_batch_fetch_import('honeypot', 'fr', Array, Object(DrushBatchContext))
> #8 /app/vendor/drush/drush/includes/batch.inc(206): _drush_batch_worker()
> #9 /app/vendor/drush/drush/includes/batch.inc(100): _drush_batch_command('414')
> #10 /app/vendor/drush/drush/src/Drupal/Commands/core/BatchCommands.php(22): drush_batch_command('414')
> #11 [internal function]: Drush\Drupal\Commands\core\BatchCommands->process('414', Array)
> #12 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
> #13 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
> #14 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
> #15 /app/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(350): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
> #16 /app/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
> #17 /app/vendor/symfony/console/Application.php(1027): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
> #18 /app/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
> #19 /app/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
> #20 /app/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
> #21 /app/vendor/drush/drush/src/Runtime/Runtime.php(48): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
> #22 /app/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
> #23 /app/vendor/drush/drush/drush(4): require('/app/vendor/dru...')
> #24 /app/vendor/bin/drush(120): include('/app/vendor/dru...')
> #25 {main}. 

Steps to reproduce

  1. You should have a multilingual site.
  2. Add a new module, e.g: composer install drupal/honeypot.
  3. Enable it: drush en honeypot.

Expected result: module is successfully enabled, no errors.

Actual result: module is enabled, but there was a php error on translations import during module install.

Proposed resolution

After some investigation it turned out that we can modify just 1 line in PoStreamReader::readLine() to fix the issue, see a patch below.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Base 

Last updated less than a minute ago

Created by

🇷🇺Russia i-grou

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Needs review over 1 year ago
  • 🇧🇪Belgium kaduk

    Patch in #7 works for me on Drupal 9.5.2!

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States smustgrave

    As a bug this will need a test case to show the error.

  • 🇺🇦Ukraine rollins

    Patch #7 resolved bug for 9.5.7 core version.
    thank you @iperiba92

  • ivnish Poland

    I had the same problem. I updated translations again here /admin/reports/translations and the problem is gone

  • Thank you for patch #7!

    I started getting this error recently, preventing module installation. The patch allowed me to install again as normal without fatal errors.

  • 🇸🇮Slovenia joco_sp

    In our case it happened on core 9.5.10. The temporary folder was not configured correctly. After adding

    $settings['file_temp_path'] = 'tmp';

    the problem went away.
    So, it's worth checking if your tmp folder is correctly configured and if it has the correct permissions before applying a patch.

  • 🇩🇪Germany Anybody Porta Westfalica

    I just ran into this in a local ddev enviroment and #16 worked. Perhaps it's a file / folder permission issue?

  • 🇧🇪Belgium flyke

    For me the solution was:
    - visit /admin/config/media/file-system
    - make sure a translations folder is set up there, like: 'sites/default/files/translations'.
    - Save the page

    Now it is fixed, if I enable another module, or drush pmu and then drush en my module again, all works good.
    I should note that when I visited /admin/config/media/file-system, a translations folder was already set up there.
    But the actual folder that is set up there was missing on my local dev environment.
    By saving that page without making any changes, Drupal created the translations folder for me.

  • 🇨🇦Canada mahde Vancouver

    I faced this issue after upgrading from Drupal 9.5.11 to Drupal 10.1.5.
    The translations directory exists and the permissions are fine.
    The temporary directory is configured correctly.
    It works only after applying the patch!

  • 🇲🇦Morocco h_kac

    I faced this issue with drupal 9.3.22 when we upgraded from PHP 7.3 to php 8.1. The comment #21 worked for me. I just saved the page without making any changes and the error was gone. When I do "drush locale-update" no more error are shown.

  • 🇫🇷France Mupsi

    Upgrading from 9.5.11 to 10.1.7, I had the same issue. What fixed it for me was a mix of #21 🐛 PoStreamReader::readLine() throws an error on module install Needs work and other things:

    • visiting /admin/config/media/file-system
    • making sure a translations folder is set up there, like: 'sites/default/files/translations'.
    • saving the form
    • running drush locale:check then drush locale:umpdate
    • finally, in /admin/reports/status, clicking on the run cron button, I get an error message saying that it failed. I clicked again and now it's working

    Hope that helps. No patch was needed for me.

  • 🇪🇸Spain rcodina

    Patch on #7 works for me on Drupal 10.1.7. In my case, the error showed up while performing a "drush deploy" in local DDEV environment. So I think it's important to show the error message but avoid interrupting the configuration import process only due to translations import failures.

  • 🇺🇦Ukraine _shY Lutsk

    Patch in #7 works for me on Drupal 10.2.3.

  • 🇦🇷Argentina matiasmiranda Yerba Buena

    The patch works, but I don't think it's the correct approach here, we're simply ignoring an error and/or misconfiguration issue.
    In my opinion this should be fixed by configuring correctly the file-system options and directory permissions.

  • 🇬🇧United Kingdom joachim

    Agree with #28 -- this is not the right fix.

    The right fix would be for the problem to produce a warning that tells users that they need to configure the temp folder.

Production build 0.69.0 2024