Avoid Translating Logged Messages in Cloudflare Module to Prevent Fatal Error

Created on 29 July 2024, 4 months ago
Updated 2 September 2024, 3 months ago

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.

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡«πŸ‡·France xavier.masson Haute-Normandie

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024