Problem/Motivation

DrupalConsoleLogger::log() passes $message to strtr() without casting it to string. PSR-3 allows Stringable messages. TranslatableMarkup is one. That causes:

TypeError: strtr(): Argument #1 ($string) must be of type string, Drupal\Core\StringTranslation\TranslatableMarkup

Steps to reproduce

\Drupal::logger('test')->warning(new TranslatableMarkup('Value %v is invalid.'), ['%v' => 'x']);

Proposed resolution

Cast $message to string before placeholder replacement.

Issue fork drupal-3616478

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

luigisa created an issue. See original summary.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Fixes need to be in MRs and as a bug test coverage

quietone’s picture

Version: 11.x-dev » main
Issue tags: +Needs merge request

Hi, thanks for the issue and the patch! Issues for Drupal core should be targeted to the 'main' branch, our primary development branch. Changes are made on the main branch first, and are then back ported as needed according to the Core change policies. The version the problem was discovered on should be stated in the issue summary Problem/Motivation section. Thanks.

If AI was used in any way to created the issue or the fix The Drupal policy is that the use must be stated on the issue. Refer to the policy on the use of AI when contributing to Drupal includes that the use of AI must be disclosed.

The needs an MR to be ready for review.

quietone’s picture

Title: DrupalConsoleLogger::log() fatals on PSR-3 Stringable messages, taking down web requests since the logger.console service is tagged as a logger » DrupalConsoleLogger::log() fatals on PSR-3 Stringable messages
Issue summary: View changes

Updating the title per Title guidelines.

luigisa’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests, -Needs merge request
luigisa’s picture

Issue summary: View changes
smustgrave’s picture

Priority: Major » Normal
Status: Needs review » Needs work

Can we extend an existing test vs adding a new one. Also can the AI verbosness be cleaned up and written in your own wording?

luigisa’s picture

Issue summary: View changes
luigisa’s picture

Moved the coverage into ConsoleTest instead of a new test class. Also trimmed the comments and the issue summary.

Thanks @smustgrave for your comment

luigisa’s picture

Status: Needs work » Needs review