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

Command icon 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:

Comments

xavier.masson created an issue. See original summary.

xavier.masson’s picture

Version: 2.0.0-beta1 » 2.0.x-dev
Status: Active » Needs review
anthonyf’s picture

Status: Needs review » Needs work

@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.

xavier.masson’s picture

Status: Needs work » Needs review

@ajfwebdev Thanks for the review, I've fixed your comments on the MR.

rosk0’s picture

Status: Needs review » Fixed

Thanks 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.

Status: Fixed » Closed (fixed)

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