Problem/Motivation
The Cloudflare module uses the $this->t() method for translating logged messages. This can cause a fatal error in some cases, specifically:
Fatal error: Call to a member function getRequestUri() on null in core/modules/locale/src/LocaleLookup.php
The error occurs when trying to add the location of a string in the {locales_source} table. The error is triggered because the translation system attempts to access the current request URI, which may not be available in certain logging contexts.
Steps to reproduce
1. Install and enable the Cloudflare module.
2. Ensure $request->server->set('HTTP_CF_CONNECTING_IP', '') to be empty for $has_http_cf_connecting_ip equals FALSE.
3. Observe the fatal error in the logs or during the request.
Proposed resolution
To resolve this issue, we propose updating the Cloudflare module to use plain text strings and sprintf for formatting messages with arguments instead of the $this->t() method. This change will prevent the translation system from attempting to translate log messages, thereby avoiding the fatal error.
Issue fork cloudflare-3464467
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3464467-avoid-translating-logged
changes, plain diff MR !22
Comments
Comment #3
xavier.massonComment #4
anthonyf commented@xavier_masson, I had some comments on your MR, so I changed the status to "Needs work". Let me know if you have any questions.
Comment #5
xavier.masson@ajfwebdev Thanks for the review, I've fixed your comments on the MR.
Comment #6
rosk0Thanks both!
This was actually fixed in #3538675: Make pipelines green, but I will mark this one as fixed to give you credits for the effort.