[Cache] Log a more readable error message when saving into cache fails

This commit is contained in:
Jérôme Deuchnord 2019-05-09 20:48:34 +02:00 committed by Nicolas Grekas
parent ecfccc6ef0
commit 21ba3c07a0
3 changed files with 10 additions and 5 deletions

View File

@ -164,7 +164,8 @@ abstract class AbstractAdapter implements AdapterInterface, CacheInterface, Logg
$ok = false; $ok = false;
$v = $values[$id]; $v = $values[$id];
$type = \is_object($v) ? \get_class($v) : \gettype($v); $type = \is_object($v) ? \get_class($v) : \gettype($v);
CacheItem::log($this->logger, 'Failed to save key "{key}" ({type})', ['key' => substr($id, \strlen($this->namespace)), 'type' => $type, 'exception' => $e instanceof \Exception ? $e : null]); $message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]);
} }
} else { } else {
foreach ($values as $id => $v) { foreach ($values as $id => $v) {
@ -186,7 +187,8 @@ abstract class AbstractAdapter implements AdapterInterface, CacheInterface, Logg
} }
$ok = false; $ok = false;
$type = \is_object($v) ? \get_class($v) : \gettype($v); $type = \is_object($v) ? \get_class($v) : \gettype($v);
CacheItem::log($this->logger, 'Failed to save key "{key}" ({type})', ['key' => substr($id, \strlen($this->namespace)), 'type' => $type, 'exception' => $e instanceof \Exception ? $e : null]); $message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]);
} }
} }

View File

@ -178,7 +178,8 @@ abstract class AbstractTagAwareAdapter implements TagAwareAdapterInterface, TagA
$ok = false; $ok = false;
$v = $values[$id]; $v = $values[$id];
$type = \is_object($v) ? \get_class($v) : \gettype($v); $type = \is_object($v) ? \get_class($v) : \gettype($v);
CacheItem::log($this->logger, 'Failed to save key "{key}" ({type})', ['key' => substr($id, \strlen($this->namespace)), 'type' => $type, 'exception' => $e instanceof \Exception ? $e : null]); $message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]);
} }
} else { } else {
foreach ($values as $id => $v) { foreach ($values as $id => $v) {
@ -201,7 +202,8 @@ abstract class AbstractTagAwareAdapter implements TagAwareAdapterInterface, TagA
} }
$ok = false; $ok = false;
$type = \is_object($v) ? \get_class($v) : \gettype($v); $type = \is_object($v) ? \get_class($v) : \gettype($v);
CacheItem::log($this->logger, 'Failed to save key "{key}" ({type})', ['key' => substr($id, \strlen($this->namespace)), 'type' => $type, 'exception' => $e instanceof \Exception ? $e : null]); $message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]);
} }
} }

View File

@ -128,7 +128,8 @@ trait ArrayTrait
$serialized = serialize($value); $serialized = serialize($value);
} catch (\Exception $e) { } catch (\Exception $e) {
$type = \is_object($value) ? \get_class($value) : \gettype($value); $type = \is_object($value) ? \get_class($value) : \gettype($value);
CacheItem::log($this->logger, 'Failed to save key "{key}" ({type})', ['key' => $key, 'type' => $type, 'exception' => $e]); $message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]);
return; return;
} }