@ndeblauw Maybe try dd-ing the $data and $meta variables’ values? Give we have absolutely no idea what function_that_fetches_data_from_external_api does or returns.
Dec 21, 2023
8
Level 10
Not understanding specific exception logic
Hi all, I'm a bit puzzled by an Undefined variable $data arror that is thrown once I reach the foreach loop, after the following try-catch block in a job:
try {
[$data, $meta] = function_that_fetches_data_from_external_api();
} catch (\Exception $exception) {
$this->fail($exception);
}
foreach ($data as $item) { // <------ here error is occuring (sometimes)
// processing of the data
}
I assumed (I guess, wrongly) that either the data (and metadata) was fetched, and the processing would be possible, or that the job would fail, and the foreach loop would never be reached.
Can somebody help me explain in what (rare?) cases the try-catch block is executed successfully, yet without the creation of a $data variable?
Please or to participate in this conversation.