Skip to content

Commit

Permalink
Handle more unexpected data types
Browse files Browse the repository at this point in the history
  • Loading branch information
jms-pantheon committed Sep 11, 2023
1 parent 8a4700d commit 4f6a86c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Collections/TerminusCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,18 @@ public function fetch()
foreach ($this->getData() as $id => $model_data) {
if (!is_object($model_data)) {
// For some reason I can't replicate, occasionally $model_data is just a string here.
$bad_data = print_r($model_data, true);
if (is_string($bad_data) && strlen($bad_data) > 250) {
$bad_data = substr($bad_data, 0, 250) . ' ...';
}
$error_message = "Fetch failed {file}:{line} model_data expected as object but returned as {type}. Unexpected value: {bad_data}";
$trace = debug_backtrace();
$error_message = "Fetch failed {file}:{line} model_data expected as object but returned as {type}.";
$context = [
'file' => $trace[0]['file'],
'line' => $trace[0]['line'],
'type' => gettype($model_data),
'bad_data' => $bad_data
];
if (is_string($model_data)) {
$error_message .= " String value: {string}";
$context['string'] = strlen($model_data) > 250 ? substr($model_data, 0, 250) . '...' : $model_data;
}
$this->logger->error($error_message, $context);
break;
}
Expand Down

0 comments on commit 4f6a86c

Please sign in to comment.