chore: Handle JSON parsing errors in format_docker_command_output_to_json

This commit is contained in:
Andras Bacsai 2024-07-18 14:23:15 +02:00
parent d98c742aff
commit ec191af874

View File

@ -48,9 +48,13 @@ function format_docker_command_output_to_json($rawOutput): Collection
$outputLines = collect($outputLines);
}
return $outputLines
->reject(fn ($line) => empty($line))
->map(fn ($outputLine) => json_decode($outputLine, true, flags: JSON_THROW_ON_ERROR));
try {
return $outputLines
->reject(fn ($line) => empty($line))
->map(fn ($outputLine) => json_decode($outputLine, true, flags: JSON_THROW_ON_ERROR));
} catch (\Throwable $e) {
return collect([]);
}
}
function format_docker_labels_to_json(string|array $rawOutput): Collection