1
0
Fork 0

Improve error messages when network failures occur

pull/1006/merge
Jordi Boggiano 2012-08-17 16:51:58 +02:00
parent a2171e2ed1
commit a54bf6269e
3 changed files with 12 additions and 3 deletions

View File

@ -85,7 +85,7 @@ class JsonFile
$json = file_get_contents($this->path); $json = file_get_contents($this->path);
} }
} catch (TransportException $e) { } 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) { } catch (\Exception $e) {
throw new \RuntimeException('Could not read '.$this->path."\n\n".$e->getMessage()); throw new \RuntimeException('Could not read '.$this->path."\n\n".$e->getMessage());
} }

View File

@ -101,6 +101,7 @@ class ComposerRepository extends ArrayRepository implements NotifiableRepository
$this->cache->write('packages.json', json_encode($data)); $this->cache->write('packages.json', json_encode($data));
} catch (\Exception $e) { } catch (\Exception $e) {
if ($contents = $this->cache->read('packages.json')) { 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>'); $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); $data = json_decode($contents, true);
} else { } else {

View File

@ -101,7 +101,15 @@ class RemoteFilesystem
$this->io->write(" Downloading: <comment>connection...</comment>", false); $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 // 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])) { if (!empty($http_response_header[0]) && preg_match('{^HTTP/\S+ 404}i', $http_response_header[0])) {
@ -148,7 +156,7 @@ class RemoteFilesystem
} }
if (false === $this->result) { 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);
} }
} }