Skip to content

Commit 7abf793

Browse files
Issue #2920943 by drunken monkey: Fixed error handling for "Rendered item" processor.
1 parent 2ca2674 commit 7abf793

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Diff for: CHANGELOG.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Search API 1.x, dev (xxxx-xx-xx):
22
---------------------------------
3+
- #2920943 by drunken monkey: Fixed error handling for "Rendered item"
4+
processor.
35

46
Search API 1.9 (2018-07-19):
57
----------------------------

Diff for: src/Plugin/search_api/processor/RenderedItem.php

+18-4
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,24 @@ public function addFieldValues(ItemInterface $item) {
268268
$view_mode = (string) $configuration['view_mode'][$datasource_id][$bundle];
269269
}
270270

271-
$build = $datasource->viewItem($item->getOriginalObject(), $view_mode);
272-
$value = (string) $this->getRenderer()->renderPlain($build);
273-
if ($value) {
274-
$field->addValue($value);
271+
try {
272+
$build = $datasource->viewItem($item->getOriginalObject(), $view_mode);
273+
$value = (string) $this->getRenderer()->renderPlain($build);
274+
if ($value) {
275+
$field->addValue($value);
276+
}
277+
}
278+
catch (\Exception $e) {
279+
// This could throw all kinds of exceptions in specific scenarios, so we
280+
// just catch all of them here. Not having a field value for this field
281+
// probably makes sense in that case, so we just log an error and
282+
// continue.
283+
$variables = [
284+
'%item_id' => $item->getId(),
285+
'%view_mode' => $view_mode,
286+
'%index' => $this->index->label(),
287+
];
288+
$this->logException($e, '%type while trying to render item %item_id with view mode %view_mode for search index %index: @message in %function (line %line of %file).', $variables);
275289
}
276290
}
277291

0 commit comments

Comments
 (0)