From fe4516aff874e17c33a951400213dc518bf6a284 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 8 Sep 2012 02:00:02 +0200 Subject: [PATCH] Clarify exception messages when a package can not be loaded from a composer repository, fixes #1070 --- src/Composer/Repository/ComposerRepository.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 0ea86e5e8..82cb0c56a 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -135,7 +135,7 @@ class ComposerRepository extends ArrayRepository implements NotifiableRepository } foreach ($this->rawData as $package) { - if (false === call_user_func($callback, $package = $this->loader->load($package, $class))) { + if (false === call_user_func($callback, $package = $this->createPackage($package, $class))) { return false; } if ($package->getAlias()) { @@ -153,7 +153,7 @@ class ComposerRepository extends ArrayRepository implements NotifiableRepository */ public function loadPackage(array $data) { - $package = $this->loader->load($data['raw'], 'Composer\Package\Package'); + $package = $this->createPackage($data['raw'], 'Composer\Package\Package'); $package->setRepository($this); return $package; @@ -180,7 +180,7 @@ class ComposerRepository extends ArrayRepository implements NotifiableRepository $repoData = $this->loadDataFromServer(); foreach ($repoData as $package) { - $this->addPackage($this->loader->load($package, 'Composer\Package\CompletePackage')); + $this->addPackage($this->createPackage($package, 'Composer\Package\CompletePackage')); } } @@ -262,4 +262,13 @@ class ComposerRepository extends ArrayRepository implements NotifiableRepository return $packages; } + + protected function createPackage(array $data, $class) + { + try { + return $this->loader->load($data, 'Composer\Package\CompletePackage'); + } catch (\Exception $e) { + throw new \RuntimeException('Could not load package '.$data['name'].' in '.$this->url.': ['.get_class($e).'] '.$e->getMessage()); + } + } }