1
0
Fork 0

Detect and hint for solutions for common curl errors, fixes #9376

pull/9380/head
Jordi Boggiano 2020-10-30 09:56:58 +01:00
parent 472f78bff1
commit 34bdc6cbf2
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
4 changed files with 41 additions and 1 deletions

View File

@ -224,6 +224,12 @@ EOT
try {
$this->httpDownloader->get($proto . '://repo.packagist.org/packages.json');
} catch (TransportException $e) {
if ($hints = HttpDownloader::getExceptionHints($e)) {
foreach ($hints as $hint) {
$result[] = $hint;
}
}
$result[] = '<error>[' . get_class($e) . '] ' . $e->getMessage() . '</error>';
}

View File

@ -30,6 +30,7 @@ use Composer\IO\IOInterface;
use Composer\IO\ConsoleIO;
use Composer\Json\JsonValidationException;
use Composer\Util\ErrorHandler;
use Composer\Util\HttpDownloader;
use Composer\EventDispatcher\ScriptExecutionException;
use Composer\Exception\NoSslException;
@ -382,6 +383,12 @@ class Application extends BaseApplication
$io->writeError('<error>The following exception is caused by a lack of memory or swap, or not having swap configured</error>', true, IOInterface::QUIET);
$io->writeError('<error>Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details</error>', true, IOInterface::QUIET);
}
if ($hints = HttpDownloader::getExceptionHints($exception)) {
foreach ($hints as $hint) {
$io->writeError($hint, true, IOInterface::QUIET);
}
}
}
/**

View File

@ -157,7 +157,6 @@ class CurlDownloader
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_FOLLOWLOCATION, false);
//curl_setopt($curlHandle, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curlHandle, CURLOPT_TIMEOUT, 300);
curl_setopt($curlHandle, CURLOPT_WRITEHEADER, $headerHandle);

View File

@ -378,4 +378,32 @@ class HttpDownloader
$io->writeError('<'.$type.'>'.ucfirst($type).' from '.$url.': '.$data[$type].'</'.$type.'>');
}
}
public static function getExceptionHints(\Exception $e)
{
if (!$e instanceof TransportException) {
return;
}
if (
false !== strpos($e->getMessage(), 'Resolving timed out')
|| false !== strpos($e->getMessage(), 'Could not resolve host')
) {
Silencer::suppress();
$testConnectivity = file_get_contents('https://8.8.8.8', false, stream_context_create(array(
'ssl' => array('verify_peer' => false),
'http' => array('follow_location' => false, 'ignore_errors' => true)
)));
Silencer::restore();
if (false !== $testConnectivity) {
return array(
'<error>The following exception probably indicates you have misconfigured DNS resolver(s)</error>'
);
}
return array(
'<error>The following exception probably indicates you are offline or have misconfigured DNS resolver(s)</error>'
);
}
}
}