From f732220b8f5c2e52753a6aac37f94299b6a5bf30 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Mon, 7 Jul 2025 10:20:54 +0200 Subject: [PATCH] refactor(shared): improve error handling in getTopLevelNetworks function to return network name on invalid docker-compose.yml --- bootstrap/helpers/shared.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 9e1aa0a43..3685dcfd5 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -599,7 +599,15 @@ function getTopLevelNetworks(Service|Application $resource) try { $yaml = Yaml::parse($resource->docker_compose_raw); } catch (\Exception $e) { - throw new \RuntimeException($e->getMessage()); + // If the docker-compose.yml file is not valid, we will return the network name as the key + $topLevelNetworks = collect([ + $resource->uuid => [ + 'name' => $resource->uuid, + 'external' => true, + ], + ]); + + return $topLevelNetworks->keys(); } $services = data_get($yaml, 'services'); $topLevelNetworks = collect(data_get($yaml, 'networks', [])); @@ -653,9 +661,16 @@ function getTopLevelNetworks(Service|Application $resource) try { $yaml = Yaml::parse($resource->docker_compose_raw); } catch (\Exception $e) { - throw new \RuntimeException($e->getMessage()); + // If the docker-compose.yml file is not valid, we will return the network name as the key + $topLevelNetworks = collect([ + $resource->uuid => [ + 'name' => $resource->uuid, + 'external' => true, + ], + ]); + + return $topLevelNetworks->keys(); } - $server = $resource->destination->server; $topLevelNetworks = collect(data_get($yaml, 'networks', [])); $services = data_get($yaml, 'services'); $definedNetwork = collect([$resource->uuid]);