Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improve error messages when network failures occur

  • Loading branch information...
commit a54bf6269e97f43f1e473ff7a277283e485e0762 1 parent a2171e2
@Seldaek Seldaek authored
View
2  src/Composer/Json/JsonFile.php
@@ -85,7 +85,7 @@ public function read()
$json = file_get_contents($this->path);
}
} catch (TransportException $e) {
- throw new \RuntimeException('Could not read '.$this->path.', either you or the remote host is probably offline'."\n\n".$e->getMessage());
+ throw new \RuntimeException($e->getMessage());
} catch (\Exception $e) {
throw new \RuntimeException('Could not read '.$this->path."\n\n".$e->getMessage());
}
View
1  src/Composer/Repository/ComposerRepository.php
@@ -101,6 +101,7 @@ protected function initialize()
$this->cache->write('packages.json', json_encode($data));
} catch (\Exception $e) {
if ($contents = $this->cache->read('packages.json')) {
+ $this->io->write('<warning>'.$e->getMessage().'</warning>');
$this->io->write('<warning>'.$this->url.' could not be loaded, package information was loaded from the local cache and may be out of date</warning>');
$data = json_decode($contents, true);
} else {
View
12 src/Composer/Util/RemoteFilesystem.php
@@ -101,7 +101,15 @@ protected function get($originUrl, $fileUrl, $fileName = null, $progress = true)
$this->io->write(" Downloading: <comment>connection...</comment>", false);
}
- $result = @file_get_contents($fileUrl, false, $ctx);
+ $errorMessage = null;
+ set_error_handler(function ($code, $msg) use (&$errorMessage) {
+ $errorMessage = preg_replace('{^file_get_contents\(.+?\): }', '', $msg);
+ if (!ini_get('allow_url_fopen')) {
+ $errorMessage = 'allow_url_fopen must be enabled in php.ini ('.$errorMessage.')';
+ }
+ });
+ $result = file_get_contents($fileUrl, false, $ctx);
+ restore_error_handler();
// fix for 5.4.0 https://bugs.php.net/bug.php?id=61336
if (!empty($http_response_header[0]) && preg_match('{^HTTP/\S+ 404}i', $http_response_header[0])) {
@@ -148,7 +156,7 @@ protected function get($originUrl, $fileUrl, $fileName = null, $progress = true)
}
if (false === $this->result) {
- throw new TransportException('The "'.$fileUrl.'" file could not be downloaded');
+ throw new TransportException('The "'.$fileUrl.'" file could not be downloaded: '.$errorMessage);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.