From 4f6a86c818ad8f20165510345d3aaa02ea02ca9a Mon Sep 17 00:00:00 2001 From: Jordan Schulz Date: Mon, 11 Sep 2023 16:37:48 -0700 Subject: [PATCH] Handle more unexpected data types --- src/Collections/TerminusCollection.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Collections/TerminusCollection.php b/src/Collections/TerminusCollection.php index 4788fa410..d624d932b 100644 --- a/src/Collections/TerminusCollection.php +++ b/src/Collections/TerminusCollection.php @@ -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; }