Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ae099b7

Browse files
author
Jérôme Deuchnord
committed
Log a more readable message when trying to cache an unsupported type
1 parent ecfccc6 commit ae099b7

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/Symfony/Component/Cache/Adapter/AbstractAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function commit()
164164
$ok = false;
165165
$v = $values[$id];
166166
$type = \is_object($v) ? \get_class($v) : \gettype($v);
167-
CacheItem::log($this->logger, 'Failed to save key "{key}" ({type})', ['key' => substr($id, \strlen($this->namespace)), 'type' => $type, 'exception' => $e instanceof \Exception ? $e : null]);
167+
CacheItem::log($this->logger, \sprintf('Could not save key "%s" in cache: the %s type is not supported.', $id, $type), ['exception' => ($e instanceof \Exception) ? $e : null]);
168168
}
169169
} else {
170170
foreach ($values as $id => $v) {
@@ -186,7 +186,7 @@ public function commit()
186186
}
187187
$ok = false;
188188
$type = \is_object($v) ? \get_class($v) : \gettype($v);
189-
CacheItem::log($this->logger, 'Failed to save key "{key}" ({type})', ['key' => substr($id, \strlen($this->namespace)), 'type' => $type, 'exception' => $e instanceof \Exception ? $e : null]);
189+
CacheItem::log($this->logger, \sprintf('Could not save key "%s" in cache: the %s type is not supported.', $id, $type), ['exception' => ($e instanceof \Exception) ? $e : null]);
190190
}
191191
}
192192

src/Symfony/Component/Cache/Adapter/AbstractTagAwareAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public function commit()
178178
$ok = false;
179179
$v = $values[$id];
180180
$type = \is_object($v) ? \get_class($v) : \gettype($v);
181-
CacheItem::log($this->logger, 'Failed to save key "{key}" ({type})', ['key' => substr($id, \strlen($this->namespace)), 'type' => $type, 'exception' => $e instanceof \Exception ? $e : null]);
181+
CacheItem::log($this->logger, \sprintf('Could not save key "%s" in cache: the %s type is not supported.', $id, $type), ['exception' => ($e instanceof \Exception) ? $e : null]);
182182
}
183183
} else {
184184
foreach ($values as $id => $v) {
@@ -201,7 +201,7 @@ public function commit()
201201
}
202202
$ok = false;
203203
$type = \is_object($v) ? \get_class($v) : \gettype($v);
204-
CacheItem::log($this->logger, 'Failed to save key "{key}" ({type})', ['key' => substr($id, \strlen($this->namespace)), 'type' => $type, 'exception' => $e instanceof \Exception ? $e : null]);
204+
CacheItem::log($this->logger, \sprintf('Could not save key "%s" in cache: the %s type is not supported.', $id, $type), ['exception' => ($e instanceof \Exception) ? $e : null]);
205205
}
206206
}
207207

src/Symfony/Component/Cache/Traits/ArrayTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private function freeze($value, $key)
128128
$serialized = serialize($value);
129129
} catch (\Exception $e) {
130130
$type = \is_object($value) ? \get_class($value) : \gettype($value);
131-
CacheItem::log($this->logger, 'Failed to save key "{key}" ({type})', ['key' => $key, 'type' => $type, 'exception' => $e]);
131+
CacheItem::log($this->logger, sprintf('Could not save key "%s" in cache: the type %s is neither a scalar value nor a serializable object.', $key, $type), ['exception' => $e]);
132132

133133
return;
134134
}

0 commit comments

Comments
 (0)