Sometimes we get this error on the landing page. Any ideas what could cause it. Module weights?

Error: Call to undefined function _token_module() in field_tokens() (line 1593 of /app/web/modules/contrib/token/token.tokens.inc)#0 [internal function]: field_tokens('entity', Array, Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#1 /app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(403): call_user_func_array('field_tokens', Array)
#2 /app/web/core/lib/Drupal/Core/Utility/Token.php(304): Drupal\Core\Extension\ModuleHandler->invokeAll('tokens', Array)
#3 /app/web/modules/contrib/token/token.tokens.inc(937): Drupal\Core\Utility\Token->generate('entity', Array, Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#4 [internal function]: token_tokens('user', Array, Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#5 /app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(403): call_user_func_array('token_tokens', Array)
#6 /app/web/core/lib/Drupal/Core/Utility/Token.php(304): Drupal\Core\Extension\ModuleHandler->invokeAll('tokens', Array)
#7 /app/web/modules/contrib/filelog/filelog.tokens.inc(135): Drupal\Core\Utility\Token->generate('user', Array, Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#8 [internal function]: filelog_tokens('log', Array, Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#9 /app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(403): call_user_func_array('filelog_tokens', Array)
#10 /app/web/core/lib/Drupal/Core/Utility/Token.php(304): Drupal\Core\Extension\ModuleHandler->invokeAll('tokens', Array)
#11 /app/web/core/lib/Drupal/Core/Utility/Token.php(196): Drupal\Core\Utility\Token->generate('log', Array, Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#12 /app/web/modules/contrib/filelog/src/Logger/FileLog.php(223): Drupal\Core\Utility\Token->replace('{"time":"[log:c...', Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#13 /app/web/modules/contrib/filelog/src/Logger/FileLog.php(157): Drupal\filelog\Logger\FileLog->render(7, '/app/web/module...', Array)
#14 /app/web/core/lib/Drupal/Core/Logger/LoggerChannel.php(127): Drupal\filelog\Logger\FileLog->log(7, '/app/web/module...', Array)
#15 /app/vendor/psr/log/Psr/Log/LoggerTrait.php(127): Drupal\Core\Logger\LoggerChannel->log(7, '/app/web/module...', Array)
#16 /app/web/modules/contrib/tekla_login/src/StackMiddleware/AtcAutologin.php(139): Drupal\Core\Logger\LoggerChannel->debug('/app/web/module...')
#17 /app/web/modules/contrib/tekla_login/src/StackMiddleware/AtcAutologin.php(69): Drupal\tekla_login\StackMiddleware\AtcAutologin->handle2(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /app/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\tekla_login\StackMiddleware\AtcAutologin->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /app/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /app/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /app/web/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /app/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#23 {main}

Comments

hkirsman created an issue. See original summary.

hkirsman’s picture

Version: 7.x-1.7 » 8.x-1.7
berdir’s picture

Category: Bug report » Support request
Status: Active » Fixed
#16 /app/web/modules/contrib/tekla_login/src/StackMiddleware/AtcAutologin.php(139): Drupal\Core\Logger\LoggerChannel->debug('/app/web/module...')
#17 /app/web/modules/contrib/tekla_login/src/StackMiddleware/AtcAutologin.php(69): Drupal\tekla_login\StackMiddleware\AtcAutologin->handle2(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /app/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\tekla_login\StackMiddleware\AtcAutologin->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)

You have a middleware that is logging and then your file logging module calls token replace, all before a full bootstrap is done. I guess that's a custom module Don't do that, it's going to cause all kinds of problems like this or inconsistent caches. Middlewares are called extremely early and have to be very careful in what they do.

Either Change it to a request subscriber or remove all logging and other stuff that might trigger hooks or other things that need a full bootstrap.

hkirsman’s picture

Thank you @Berdir

Status: Fixed » Closed (fixed)

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