Skip to content

Commit 4225ec7

Browse files
committed
feat: Improve error handling in loadComposeFile method
1 parent 893339f commit 4225ec7

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

app/Models/Application.php

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,45 +1081,55 @@ public function loadComposeFile($isInit = false)
10811081
'git read-tree -mu HEAD',
10821082
"cat .$workdir$composeFile",
10831083
]);
1084-
$composeFileContent = instant_remote_process($commands, $this->destination->server, false);
1085-
if (! $composeFileContent) {
1084+
try {
1085+
$composeFileContent = instant_remote_process($commands, $this->destination->server);
1086+
} catch (\Exception $e) {
1087+
if (str($e->getMessage())->contains('No such file')) {
1088+
throw new \RuntimeException("Docker Compose file not found at: $workdir$composeFile<br><br>Check if you used the right extension (.yaml or .yml) in the compose file name.");
1089+
}
1090+
if (str($e->getMessage())->contains('fatal: repository') && str($e->getMessage())->contains('does not exist')) {
1091+
if ($this->deploymentType() === 'deploy_key') {
1092+
throw new \RuntimeException('Your deploy key does not have access to the repository. Please check your deploy key and try again.');
1093+
}
1094+
throw new \RuntimeException('Repository does not exist. Please check your repository URL and try again.');
1095+
}
1096+
throw new \RuntimeException($e->getMessage());
1097+
} finally {
10861098
$this->docker_compose_location = $initialDockerComposeLocation;
10871099
$this->save();
10881100
$commands = collect([
10891101
"rm -rf /tmp/{$uuid}",
10901102
]);
10911103
instant_remote_process($commands, $this->destination->server, false);
1092-
throw new \RuntimeException("Docker Compose file not found at: $workdir$composeFile<br><br>Check if you used the right extension (.yaml or .yml) in the compose file name.");
1093-
} else {
1104+
}
1105+
if ($composeFileContent) {
10941106
$this->docker_compose_raw = $composeFileContent;
10951107
$this->save();
1096-
}
1097-
1098-
$commands = collect([
1099-
"rm -rf /tmp/{$uuid}",
1100-
]);
1101-
instant_remote_process($commands, $this->destination->server, false);
1102-
$parsedServices = $this->parseCompose();
1103-
if ($this->docker_compose_domains) {
1104-
$json = collect(json_decode($this->docker_compose_domains));
1105-
$names = collect(data_get($parsedServices, 'services'))->keys()->toArray();
1106-
$jsonNames = $json->keys()->toArray();
1107-
$diff = array_diff($jsonNames, $names);
1108-
$json = $json->filter(function ($value, $key) use ($diff) {
1109-
return ! in_array($key, $diff);
1110-
});
1111-
if ($json) {
1112-
$this->docker_compose_domains = json_encode($json);
1113-
} else {
1114-
$this->docker_compose_domains = null;
1108+
$parsedServices = $this->parseCompose();
1109+
if ($this->docker_compose_domains) {
1110+
$json = collect(json_decode($this->docker_compose_domains));
1111+
$names = collect(data_get($parsedServices, 'services'))->keys()->toArray();
1112+
$jsonNames = $json->keys()->toArray();
1113+
$diff = array_diff($jsonNames, $names);
1114+
$json = $json->filter(function ($value, $key) use ($diff) {
1115+
return ! in_array($key, $diff);
1116+
});
1117+
if ($json) {
1118+
$this->docker_compose_domains = json_encode($json);
1119+
} else {
1120+
$this->docker_compose_domains = null;
1121+
}
1122+
$this->save();
11151123
}
1116-
$this->save();
1124+
1125+
return [
1126+
'parsedServices' => $parsedServices,
1127+
'initialDockerComposeLocation' => $this->docker_compose_location,
1128+
];
1129+
} else {
1130+
throw new \RuntimeException("Docker Compose file not found at: $workdir$composeFile<br><br>Check if you used the right extension (.yaml or .yml) in the compose file name.");
11171131
}
11181132

1119-
return [
1120-
'parsedServices' => $parsedServices,
1121-
'initialDockerComposeLocation' => $this->docker_compose_location,
1122-
];
11231133
}
11241134

11251135
public function parseContainerLabels(?ApplicationPreview $preview = null)

0 commit comments

Comments
 (0)