This commit is contained in:
nuno maduro
2026-05-02 18:03:25 +01:00
parent 31c200716d
commit 380ccd30b4

View File

@ -651,44 +651,36 @@ YAML;
return ['kind' => 'unknown', 'message' => 'unknown error']; return ['kind' => 'unknown', 'message' => 'unknown error'];
} }
if (preg_match('/(could not resolve host|connection refused|connection reset|temporary failure in name resolution|network is unreachable|no route to host|i\/o timeout|tls handshake|getaddrinfo)/i', $output) === 1) { $diagnoses = [
return [ 'network' => [
'kind' => 'network', 'pattern' => '/could not resolve host|connection refused|connection reset|temporary failure in name resolution|network is unreachable|no route to host|i\/o timeout|tls handshake|getaddrinfo/i',
'message' => 'network error (offline or DNS unreachable). Try again when connected.', 'message' => 'network error (offline or DNS unreachable). Try again when connected.',
]; ],
} 'gh-auth' => [
'pattern' => '/authentication failed|not logged in|requires authentication|bad credentials|401/i',
if (preg_match('/(authentication failed|not logged in|requires authentication|bad credentials|401)/i', $output) === 1) {
return [
'kind' => 'gh-auth',
'message' => 'authentication failed — run `gh auth login` and retry.', 'message' => 'authentication failed — run `gh auth login` and retry.',
]; ],
} 'rate-limit' => [
'pattern' => '/rate limit|too many requests|secondary rate limit/i',
if (preg_match('/(rate limit|too many requests|secondary rate limit)/i', $output) === 1) {
return [
'kind' => 'rate-limit',
'message' => 'GitHub API rate limit hit — try again later.', 'message' => 'GitHub API rate limit hit — try again later.',
]; ],
} 'not-found' => [
'pattern' => '/404|not found|repository not found/i',
if (preg_match('/(404|not found|repository not found)/i', $output) === 1) {
return [
'kind' => 'not-found',
'message' => 'workflow or artifact not found in repo.', 'message' => 'workflow or artifact not found in repo.',
]; ],
} 'forbidden' => [
'pattern' => '/403|forbidden|access denied/i',
if (preg_match('/(403|forbidden|access denied)/i', $output) === 1) {
return [
'kind' => 'forbidden',
'message' => 'access denied — check that your `gh` token has repo + actions read scope.', 'message' => 'access denied — check that your `gh` token has repo + actions read scope.',
]; ],
];
foreach ($diagnoses as $kind => $diagnosis) {
if (preg_match($diagnosis['pattern'], $output) === 1) {
return ['kind' => $kind, 'message' => $diagnosis['message']];
}
} }
$message = trim(strtok($output, "\n")); return ['kind' => 'unknown', 'message' => trim(strtok($output, "\n"))];
return ['kind' => 'unknown', 'message' => $message];
} }
private function commandExists(string $cmd): bool private function commandExists(string $cmd): bool