Skip to content

[Cache] Error message does not contain cache-adapter placeholder, so it will not populated #48504

Closed
@holtkamp

Description

@holtkamp

Symfony version(s) affected

6.2.0

Description

When a CacheAdapter logs an error using CacheItem::log(), an array with context information is provided. Often this array also include the 'cache-adapter' => get_debug_type($this) to handover the name of the cache adapter to the error message, which is useful when multiple CacheAdapters are involved.

https://github.com/symfony/cache/blob/64cb231dfb25677097d18503d1ad4d016b19f19c/Adapter/AbstractAdapter.php#L182-L183

However, since the message itself does not contain the cache-adapter placeholder, this information is not included in the eventual error message.

https://github.com/symfony/cache/blob/64cb231dfb25677097d18503d1ad4d016b19f19c/CacheItem.php#L155-L161

When a PSR Logger is assigned to the CacheAdapter, this might not be a big problem (since the context is handed over and used in another way). But when trigger_error is used, this information is really lost.

How to reproduce

Have a CacheAdapter log a messages using CacheItem::log() and check whether the name of the CacheAdapter end up in the error message of the logs.

Possible Solution

Include {cache-adapter} placeholder in the error message, for example:

$message = sprintf('Failed to save key "{key}" of type %s%s to CacheAdapter "{cache-adapter}"', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null, 'cache-adapter' => get_debug_type($this)]);

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions