Error message :

The website encountered an unexpected error. Please try again later.
ArgumentCountError: Too few arguments to function Drupal\twig_field_value\Twig\Extension\FieldValueExtension::__construct(), 0 passed in /app/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 262 and exactly 2 expected in Drupal\twig_field_value\Twig\Extension\FieldValueExtension->__construct() (line 44 of modules/composer/twig_field_value/src/Twig/Extension/FieldValueExtension.php).
Drupal\twig_field_value\Twig\Extension\FieldValueExtension->__construct() (Line: 262)
Drupal\Component\DependencyInjection\Container->createService(Array, 'twig_field_value.twig.extension') (Line: 176)
Drupal\Component\DependencyInjection\Container->get('twig_field_value.twig.extension', 1) (Line: 437)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 276)
Drupal\Component\DependencyInjection\Container->createService(Array, 'twig') (Line: 176)
Drupal\Component\DependencyInjection\Container->get('twig') (Line: 197)
Drupal::service('twig') (Line: 47)
twig_render_template('core/themes/seven/templates/classy/dataset/table.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('table', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 164)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Rolled back to 2.0.0 and everything started working again.

This was seen when I tried to view the Image styles interface at : /admin/config/media/image-styles

Comments

alphex created an issue. See original summary.

sutharsan’s picture

Did you run update scripts? I expect that to clear the cache, which should prevent this.

steveoriol’s picture

I get the same error message as alphex...
even after an "drush updb -y && drush cr"
I have D9.4.8 and PHP 8.0.23

and back to v2.0.0 ; it is working again.

pp.panatom’s picture

had the same error
no errors on website, but with several drush commands, like drush cex or drush status

so i did cache rebuild via UI (not drush), after that the error was gone

hanan alasari’s picture

I get the same error message for D9.4.8. need to back to v2.0.0.

jacqui.tenderwolf’s picture

I am also having this error after the upgrade, but not for all my sites, just one.

sutharsan’s picture

Perhaps this helps:

function twig_field_value_update_8001() {
  \Drupal::service('kernel')->invalidateContainer();
}
sutharsan’s picture

Status: Active » Postponed (maintainer needs more info)

I can not reproduce the bug and can therefore not fix it without contributions. Either code that prevents the bug or steps to reproduce it.

pameeela’s picture

@Sutharsan have you tried with PHP 8? I am getting the same error, it only goes away if I downgrade PHP to 7.4.

sutharsan’s picture

@pameeela, I tried with both.

I can not reproduce with:

  • ddev environment 1.19.1 on OSX
  • PHP 8.1
  • Drupal 9.4.8
  • Drush 10.6.2
  • Drupal core + twig_field_value 2.0.0 -> 2.0.1
  • An node template with {{ content.body|field_raw['format'] }}
alphex’s picture

I'm running ....

On Lando v3.6.5

Docker 4.8.1 (78998)

Drupal 9.4.8

PHP 8.0.19

10.4.21-MariaDB-1:10.4.21+maria~focal

nginx/1.16.1

-----

Setting my composer.json file to "drupal/twig_field_value": "2.0.1",

And running composer update && lando drush cr && lando drush updb -y

... I go and visit "/admin/config/media/image-styles" from my original error report, and.... no longer receive the error.

I normally run lando drush cr and lando drush updb -y after any module changes... sooo, maybe we just need to do it a few more times :)

When it doubt, clear cache -- again.

Thank you.

pp.panatom’s picture

@sutharsan
the install hook (#7) worked for me

olekstkach’s picture

StatusFileSize
new416 bytes
sutharsan’s picture

+++ b/twig_field_value.install
@@ -0,0 +1,13 @@
+ * Implements hook_install().
+ */
+function twig_field_value_install() {

Please explain why an install hook is the solution to the problem. This patch is not the same as the proposed solution in #7

pyretta’s picture

Hi,
I also can't run the update via composer.
Page is completely unusable afterwards (frontend & backend): "The website encountered an unexpected error. Please try again later."

Drupal: 9.4.8
PHP: 8.1.10
DB: 8.0.30 MySQL, Percona Server
Composer: 2.2.6
Drush: 11.0.5

In which file should the hook suggested in #7 be inserted as a workaround?
Do I need to create a separate module for this?

here are the composer commands I used:

composer update drupal/twig_field_value --with-dependencies
./vendor/bin/drush updatedb
./vendor/bin/drush cache-rebuild

Maybe it helps to reproduce the error?

jim22’s picture

Same issue. WSOD after update to 2.0.1. I've run drush updb and cr many times.

Drupal Version 9.4.7
PHP Version 8.0.23
hosted on Acquia Cloud, but interestingly enough I'm not getting WSOD/error in my local Lando env

Also tried following with no luck:

function twig_field_value_update_8001() {
  \Drupal::service('kernel')->invalidateContainer();
}

Reverting to 2.0.0 for now.

Pasting error:
ArgumentCountError: Too few arguments to function Drupal\twig_field_value\Twig\Extension\FieldValueExtension::__construct(), 0 passed in /var/www/html/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php on line 262 and exactly 2 expected in /var/www/html/docroot/modules/contrib/twig_field_value/src/Twig/Extension/FieldValueExtension.php on line 44 #0 /var/www/html/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(262): Drupal\twig_field_value\Twig\Extension\FieldValueExtension->__construct()

sutharsan’s picture

Always clear the cache before you run the update script. See step 4 and 5 in https://www.drupal.org/docs/updating-drupal/updating-drupal-core-via-drush

cwyattjibc’s picture

I had the same error.

Drupal core 9.3.22
twig_field_value:2.0.1
PHP 7.4

I updated the database and cleared the cache and my site is back up.

I'm watching recent log messages to make sure the PHP error doesn't come back.

jim22’s picture

Update: Apologies, I believe my issue was related to my server - ssh + drush. Clearing cache and running database updates fixes the error.

vrancje’s picture

I'm having the same error:

Drupal Version: 9.4.7
twig_field_value:2.0.1
PHP Version: 8.0.23

Also did updb and cr

Patch #13 works for me!

sutharsan’s picture

Patch #13 is a placebo, it does not actually do anything during update. Hook_install performs setup tasks when the module is installed.

I think the fact that it seems to work is that, during the process of trying again, an additional cache rebuild is performed.

I can only be convinced by instructions to reproduce the error, on ddev, a docker environment or a virtual machine.

loker’s picture

Same for me...

I'm using 9.4.8 with php 7.4.3 on Ubuntu. When I upgrade to the latest (2.0.1) I get
ArgumentCountError: Too few arguments to function Drupal\\twig_field_value\\Twig\\Extension\\FieldValueExtension::__construct(), 0 passed in (...)/Drupal/Component/DependencyInjection/Container.php on line 262 and exactly 2 expected in (...) web/modules/contrib/twig_field_value/src/Twig/Extension/FieldValueExtension.php on line 44 (...)

I have cleared the cache but it didn't help. I didn't understand the proposed solution on #7, where should I try that snippet?

loker’s picture

I have tried with 2.0.2 today, after upgrading the base system to 9.5 with hope, but this issue still exists.

ArgumentCountError: Too few arguments to function Drupal\\twig_field_value\\Twig\\Extension\\FieldValueExtension::__construct(), 0 passed in /(...)/core/lib/Drupal/Component/DependencyInjection/Container.php on line 263 and exactly 4 expected in /(...)/web/modules/contrib/twig_field_value/src/Twig/Extension/FieldValueExtension.php on line 67.

sutharsan’s picture

@loker Have you cleared the cache after changing the code and before running the update script?

With drush:

drush cr
drush updb
drush cim

or

drush cr
drush deploy
loker’s picture

@Sutharsan, yes I have cleared the cache with drush, and just to be sure with front end as well. The site I had problems with was a multi-site installation, maybe it had something to do with that, I don't know. As I couldn't find a solution, I took another path and uninstalled your module. Sorry.

Webbeh’s picture

We had this happen with single-site installations in a limited hosting environment (higher-ed) without drush access (yes, I know, it's miserable).

For us problem environments, it's always helpful to have a cache invalidator during db-updates so that we don't immediately get a WSOD due to an outdated cache.

breezeweb’s picture

This issue is still occurring in 2.0.2, reverting it back to 2.0.0 fixed it.

mohitgupta.ald’s picture

Tried with version 2.0.2, did the drush updb from console, and then cleared out the cache from frontend but still received WSOD. Reverting it back to 2.0.0 fixed it.

mohitgupta.ald’s picture

It will be great if someone provide any working patch from upgrading the module to 2.0.2.

Webbeh’s picture

As a reminder, to fix this, we need to find a reproducible process to recreate this issue.

The steps should begin with: install Drupal using a default profile, install version 2.0.0, then upgrade, and see error; or, to find a process that reproduces this.

rick hood’s picture

StatusFileSize
new12.41 KB

I am getting errors.

Steps to reproduce (on my local using Lando):

1. composer update drupal/twig_field_value
Upgrading drupal/twig_field_value (2.0.1 => 2.0.2)

2. lando drush updb
[success] No pending updates.

3. I get errors on all page similar to error below

4. lando drush cr
Gets rid of the errors.
However, a concern is that I could not clear cache via the interface because this page also have errors: /admin/config/development/performance

I am holding off deploying this live for now.

The website encountered an unexpected error. Please try again later.
TypeError: Drupal\twig_field_value\Twig\Extension\FieldValueExtension::__construct(): Argument #1 ($language_manager) must be of type Drupal\Core\Language\LanguageManagerInterface, Drupal\Core\Controller\ControllerResolver given, called in /app/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 in Drupal\twig_field_value\Twig\Extension\FieldValueExtension->__construct() (line 67 of modules/contrib/twig_field_value/src/Twig/Extension/FieldValueExtension.php).

....etc.

full output of errors is in the attached file.

grevil’s picture

Version: 2.0.1 » 2.0.x-dev

Is this still a problem for latest dev?