Add constants to describe error codes from Installer::run
parent
79727d35c4
commit
260ac0011c
|
@ -21,6 +21,8 @@ use Composer\Package\PackageInterface;
|
|||
*/
|
||||
class SolverProblemsException extends \RuntimeException
|
||||
{
|
||||
const ERROR_DEPENDENCY_RESOLUTION_FAILED = 2;
|
||||
|
||||
/** @var Problem[] */
|
||||
protected $problems;
|
||||
/** @var array<Rule[]> */
|
||||
|
@ -35,7 +37,7 @@ class SolverProblemsException extends \RuntimeException
|
|||
$this->problems = $problems;
|
||||
$this->learnedPool = $learnedPool;
|
||||
|
||||
parent::__construct('Failed resolving dependencies with '.count($problems).' problems, call getPrettyString to get formatted details', 2);
|
||||
parent::__construct('Failed resolving dependencies with '.count($problems).' problems, call getPrettyString to get formatted details', self::ERROR_DEPENDENCY_RESOLUTION_FAILED);
|
||||
}
|
||||
|
||||
public function getPrettyString(RepositorySet $repositorySet, Request $request, Pool $pool, $isVerbose, $isDevExtraction = false)
|
||||
|
|
|
@ -66,6 +66,13 @@ use Composer\Util\Platform;
|
|||
*/
|
||||
class Installer
|
||||
{
|
||||
const ERROR_NONE = 0; // no error/success state
|
||||
const ERROR_GENERIC_FAILURE = 1;
|
||||
const ERROR_NO_LOCK_FILE_FOR_PARTIAL_UPDATE = 3;
|
||||
const ERROR_LOCK_FILE_INVALID = 4;
|
||||
// used/declared in SolverProblemsException, carried over here for completeness
|
||||
const ERROR_DEPENDENCY_RESOLUTION_FAILED = 2;
|
||||
|
||||
/**
|
||||
* @var IOInterface
|
||||
*/
|
||||
|
@ -209,6 +216,7 @@ class Installer
|
|||
*
|
||||
* @throws \Exception
|
||||
* @return int 0 on success or a positive error code on failure
|
||||
* @phpstan-return self::ERROR_*
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
|
@ -387,7 +395,7 @@ class Installer
|
|||
if (($this->updateAllowList || $this->updateMirrors) && !$lockedRepository) {
|
||||
$this->io->writeError('<error>Cannot update ' . ($this->updateMirrors ? 'lock file information' : 'only a partial set of packages') . ' without a lock file present. Run `composer update` to generate a lock file.</error>', true, IOInterface::QUIET);
|
||||
|
||||
return 1;
|
||||
return self::ERROR_NO_LOCK_FILE_FOR_PARTIAL_UPDATE;
|
||||
}
|
||||
|
||||
$this->io->writeError('<info>Loading composer repositories with package information</info>');
|
||||
|
@ -434,7 +442,7 @@ class Installer
|
|||
$ghe = new GithubActionError($this->io);
|
||||
$ghe->emit($err."\n".$prettyProblem);
|
||||
|
||||
return max(1, $e->getCode());
|
||||
return max(self::ERROR_GENERIC_FAILURE, $e->getCode());
|
||||
}
|
||||
|
||||
$this->io->writeError("Analyzed ".count($pool)." packages to resolve dependencies", true, IOInterface::VERBOSE);
|
||||
|
@ -603,7 +611,7 @@ class Installer
|
|||
$ghe = new GithubActionError($this->io);
|
||||
$ghe->emit($err."\n".$prettyProblem);
|
||||
|
||||
return max(1, $e->getCode());
|
||||
return max(self::ERROR_GENERIC_FAILURE, $e->getCode());
|
||||
}
|
||||
|
||||
$lockTransaction->setNonDevPackages($nonDevLockTransaction);
|
||||
|
@ -661,7 +669,7 @@ class Installer
|
|||
if (0 !== count($lockTransaction->getOperations())) {
|
||||
$this->io->writeError('<error>Your lock file cannot be installed on this system without changes. Please run composer update.</error>', true, IOInterface::QUIET);
|
||||
|
||||
return 1;
|
||||
return self::ERROR_LOCK_FILE_INVALID;
|
||||
}
|
||||
} catch (SolverProblemsException $e) {
|
||||
$err = 'Your lock file does not contain a compatible set of packages. Please run composer update.';
|
||||
|
@ -673,7 +681,7 @@ class Installer
|
|||
$ghe = new GithubActionError($this->io);
|
||||
$ghe->emit($err."\n".$prettyProblem);
|
||||
|
||||
return max(1, $e->getCode());
|
||||
return max(self::ERROR_GENERIC_FAILURE, $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,5 +33,5 @@ update b/unstable
|
|||
--EXPECT-OUTPUT--
|
||||
Cannot update only a partial set of packages without a lock file present. Run `composer update` to generate a lock file.
|
||||
--EXPECT-EXIT-CODE--
|
||||
1
|
||||
3
|
||||
--EXPECT--
|
||||
|
|
Loading…
Reference in New Issue