PHP Fatal error: ContainerNotInitializedException thrown while calling __toString on a TranslatableMarkup

Created on 30 June 2021, over 3 years ago
Updated 13 September 2023, about 1 year ago

Installed this module and the correct core-dev package. When I try to scan any module (either via UI or drush), I get the following:

PHPStan command failed: /app/vendor/bin/phpstan analyse --error-format=json -c /var/www/tmp/upgrade_status/deprecation_testing.neon /app/web/modules/custom/activecampaign 2> /var/www/tmp/upgrade_status/phpstan_error_output Command output: Empty. Command error: PHP Fatal error:  Drupal\Core\DependencyInjection\ContainerNotInitializedException thrown while calling __toString on a Drupal\Core\StringTranslation\TranslatableMarkup object in /app/web/core/lib/Drupal.php on line 130: \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container. in /app/web/core/lib/Drupal/Component/Utility/ToStringTrait.php on line 20
Fatal error: Drupal\Core\DependencyInjection\ContainerNotInitializedException thrown while calling __toString on a Drupal\Core\StringTranslation\TranslatableMarkup object in /app/web/core/lib/Drupal.php on line 130: \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container. in /app/web/core/lib/Drupal/Component/Utility/ToStringTrait.php on line 20 
πŸ› Bug report
Status

Postponed: needs info

Version

3.7

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jaymcgraw

Live updates comments and jobs are added and updated live.
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.

  • πŸ‡ΊπŸ‡¦Ukraine mostepaniukvm

    I've faced similar issues.
    Project widely uses module_load_include()
    I replaced it with \Drupal::moduleHandler()->loadInclude() and it solved most of the problems.

    However, when dealing with multiple nested includes, PHPStan throws an exception: "\Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container."

    As result, in "LOCAL SCAN RESULT" column of upgrade-status report I see reported problem with message: "A file could not be loaded from Drupal\Core\Extension\ModuleHandlerInterface::loadInclude"

  • πŸ‡­πŸ‡ΊHungary GΓ‘bor Hojtsy Hungary

    @mostepaniukvm you mean your scanned project code uses module_load_include()? (Upgrade Status does not). I think phpstan-drupal is supposed to work around this by providing a mock container.

  • πŸ‡ΊπŸ‡¦Ukraine mostepaniukvm

    Yes, it's client's project was using tons of module_load_include()
    I was using latest phpstan-drupal 1.2.0
    I agree that it sounds like phpstan-drupal problem and not upgrade_status.
    Will test again, describe steps and report issue to phpstan-drupal

  • πŸ‡ΊπŸ‡ΈUnited States bobburns

    Same here

  • πŸ‡¦πŸ‡ΉAustria maxilein

    I'd like to add something I believe could be connected
    https://www.drupal.org/project/upgrade_status/issues/3481662 πŸ’¬ Phpstan failed Active

Production build 0.71.5 2024