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
smustgrave’s picture

Assigned: luigisa » Unassigned
Status: Needs review » Needs work

So I checked Psr\Log\LoggerTrait and it has String|\Stringable as a typehint. So I think we need to add here too but because of BC we can't. Think the best route would be to check the $message variable is not Stringable trigger a deprecation that in D13 it will be required.

zeeshan_khan made their first commit to this issue’s fork.

zeeshan_khan’s picture

Status: Needs work » Needs review
zeeshan_khan’s picture

Disclosure: AI was used to investigate and find better solution then manually reviewed and fixed the issue

idebr’s picture

Status: Needs review » Needs work
Issue tags: +Needs change record

Bumped into this error when upgrading a project from Drupal 10 to Drupal 11.

The issue is fixed with the change suggested in https://git.drupalcode.org/project/drupal/-/merge_requests/16704

To my understanding, the deprecation should link to a change record and not the issue itself according to https://www.drupal.org/about/core/policies/core-change-policies/how-to-d...

Actionable items:

  1. This issue needs a change record describing the stringable requirement
  2. The merge request needs to be updated to point to the change record created in 1.