From feda2a283f1b545444e31e9e01cf9dffb9ff304c Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 18 Apr 2016 23:03:00 +0100 Subject: [PATCH] Improve error reporting some more, fixes #4310 --- src/Composer/DependencyResolver/Problem.php | 4 ++-- src/Composer/DependencyResolver/Rule.php | 2 +- src/Composer/Installer.php | 4 ++++ .../Fixtures/installer/solver-problems.test | 20 ++++++++++++++----- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Composer/DependencyResolver/Problem.php b/src/Composer/DependencyResolver/Problem.php index 474c07b43..d42ca4774 100644 --- a/src/Composer/DependencyResolver/Problem.php +++ b/src/Composer/DependencyResolver/Problem.php @@ -130,11 +130,11 @@ class Problem } if ($providers = $this->pool->whatProvides($job['packageName'], $job['constraint'], true, true)) { - return "\n - The requested package ".$job['packageName'].$this->constraintToText($job['constraint']).' is satisfiable by '.$this->getPackageList($providers).' but those are rejected by your minimum-stability.'; + return "\n - The requested package ".$job['packageName'].$this->constraintToText($job['constraint']).' is satisfiable by '.$this->getPackageList($providers).' but these conflict with your requirements or minimum-stability.'; } if ($providers = $this->pool->whatProvides($job['packageName'], null, true, true)) { - return "\n - The requested package ".$job['packageName'].$this->constraintToText($job['constraint']).' exists as '.$this->getPackageList($providers).' but those are rejected by your constraint.'; + return "\n - The requested package ".$job['packageName'].$this->constraintToText($job['constraint']).' exists as '.$this->getPackageList($providers).' but these are rejected by your constraint.'; } return "\n - The requested package ".$job['packageName'].' could not be found in any version, there may be a typo in the package name.'; diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index 2f2d61b8f..dc10391be 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -241,7 +241,7 @@ class Rule return $text . ' -> the requested linked library '.$lib.' has the wrong version installed or is missing from your system, make sure to have the extension providing it.'; } else { if ($providers = $pool->whatProvides($targetName, $this->reasonData->getConstraint(), true, true)) { - return $text . ' -> satisfiable by ' . $this->formatPackagesUnique($pool, $providers) .' but these conflict with your requirements or minimum-stability'; + return $text . ' -> satisfiable by ' . $this->formatPackagesUnique($pool, $providers) .' but these conflict with your requirements or minimum-stability.'; } return $text . ' -> no matching package found.'; diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 8f9c51c51..e1f0011e0 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -448,6 +448,7 @@ class Installer $candidates = array(); foreach ($links as $link) { $candidates[$link->getTarget()] = true; + $rootRequires[$link->getTarget()] = $link; } foreach ($localRepo->getPackages() as $package) { $candidates[$package->getName()] = true; @@ -459,6 +460,9 @@ class Installer if ($curPackage->getName() === $candidate) { if (!$this->isUpdateable($curPackage) && !isset($removedUnstablePackages[$curPackage->getName()])) { $constraint = new Constraint('=', $curPackage->getVersion()); + $description = $this->locker->isLocked() ? '(locked at' : '(installed at'; + $requiredAt = isset($rootRequires[$candidate]) ? ', required as ' . $rootRequires[$candidate]->getPrettyConstraint() : ''; + $constraint->setPrettyString($description . ' ' . $curPackage->getPrettyVersion() . $requiredAt . ')'); $request->install($curPackage->getName(), $constraint); } break; diff --git a/tests/Composer/Test/Fixtures/installer/solver-problems.test b/tests/Composer/Test/Fixtures/installer/solver-problems.test index 87c4fa7ee..605bd3cae 100644 --- a/tests/Composer/Test/Fixtures/installer/solver-problems.test +++ b/tests/Composer/Test/Fixtures/installer/solver-problems.test @@ -10,7 +10,9 @@ Test the error output of solver problems. { "name": "unstable/package", "version": "1.0.0" }, { "name": "requirer", "version": "1.0.0", "require": {"dependency": "1.0.0" } }, { "name": "dependency", "version": "2.0.0" }, - { "name": "dependency", "version": "1.0.0" } + { "name": "dependency", "version": "1.0.0" }, + { "name": "stable-requiree-excluded", "version": "1.0.1" }, + { "name": "stable-requiree-excluded", "version": "1.0.0" } ] } ], @@ -18,12 +20,18 @@ Test the error output of solver problems. "unstable/package": "2.*", "bogus": "1.*", "requirer": "1.*", - "dependency": "2.*" + "dependency": "2.*", + "stable-requiree-excluded": "1.0.1" } } +--INSTALLED-- +[ + { "name": "stable-requiree-excluded", "version": "1.0.0" } +] + --RUN-- -install +update unstable/package requirer dependency --EXPECT-EXIT-CODE-- 2 @@ -34,12 +42,14 @@ Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. Problem 1 - - The requested package unstable/package 2.* exists as unstable/package[1.0.0] but those are rejected by your constraint. + - The requested package unstable/package 2.* exists as unstable/package[1.0.0] but these are rejected by your constraint. Problem 2 - The requested package bogus could not be found in any version, there may be a typo in the package name. Problem 3 + - The requested package stable-requiree-excluded (installed at 1.0.0, required as 1.0.1) is satisfiable by stable-requiree-excluded[1.0.0] but these conflict with your requirements or minimum-stability. + Problem 4 - Installation request for requirer 1.* -> satisfiable by requirer[1.0.0]. - - requirer 1.0.0 requires dependency 1.0.0 -> satisfiable by dependency[1.0.0] but these conflict with your requirements or minimum-stability + - requirer 1.0.0 requires dependency 1.0.0 -> satisfiable by dependency[1.0.0] but these conflict with your requirements or minimum-stability. Potential causes: - A typo in the package name