phar-io/version · error · UnsupportedVersionConstraintException

Version constraint is not supported.

Error message

Version constraint %s is not supported.

What it means

UnsupportedVersionConstraintException is thrown by VersionConstraintParser::parse when the constraint string does not match '/^[\^~*]?v?[\d.*]+(?:-.*)?$/i'. The parser supports only simple constraints: exact versions, wildcards (*, 1.*), caret (^) and tilde (~) ranges, and OR groups separated by '|'. Operators like '>=', '<', ranges with spaces ('1.0 - 2.0') or comma-separated AND lists are not supported.

Solutions

  1. Rewrite the constraint using supported syntax: plain versions, *, prefix wildcards, ^, ~, and single '|' OR groups (e.g. '>=1.0 <2.0' has no direct equivalent — enumerate alternatives like '1.0.*|1.1.*' if possible).
  2. Pre-validate the constraint against the accepted regex and fall back to another parser (e.g. Composer's full Semver) for unsupported operators.
  3. Split complex AND/OR logic in application code: parse individual supported constraints and combine matches() results manually.

Example fix

// before
$constraint = (new VersionConstraintParser())->parse('>=7.4 <8.0');

// after
$parser = new VersionConstraintParser();
$lower = $parser->parse('7.4');
$upper = $parser->parse('8.0.0');
// compare with Version::isGreaterThan/isLessThan instead of an unsupported range string
Defensive patterns

Strategy: validation

Validate before calling

// PHP
if (!preg_match('/^[\^~*]?v?[\d.*]+(?:-.*)?$/i', $constraint)) {
    throw new InvalidArgumentException("Constraint not supported by VersionConstraintParser: $constraint");
}

Try / catch

try {
    $c = $parser->parse($value);
} catch (UnsupportedVersionConstraintException $e) {
    // fall back to Composer\Semver\Semver or reject the config value
}

Prevention

When it happens

Trigger: Calling (new VersionConstraintParser)->parse('>=1.0.0 <2.0.0'), parse('1.0.0 - 2.0.0'), parse('~1.2, ~1.3'), or any string containing characters outside the allowed set; handleOrGroup forwards each '|' separated part back through parse, so one bad part throws.

Common situations: Reusing Composer-style constraints ('^1.2 || >=2.0', 'dev-main') with this simpler parser; config files authored for Composer being fed to composer/semver's VersionConstraintParser; copy-pasted range syntax from npm ('1.x.x || >=2.3.0').

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of phar-io/version@5eeb03f1ee (2026-09-14). Data as JSON: /api/errors/0f6a717830af11f7. Report an issue: GitHub.

Appendix: source

Thrown at src/VersionConstraintParser.php:22

 *
 * (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace PharIo\Version;

class VersionConstraintParser {
    /**
     * @throws UnsupportedVersionConstraintException
     */
    public function parse(string $value): VersionConstraint {
        if (\strpos($value, '|') !== false) {
            return $this->handleOrGroup($value);
        }

        if (!\preg_match('/^[\^~*]?v?[\d.*]+(?:-.*)?$/i', $value)) {
            throw new UnsupportedVersionConstraintException(
                \sprintf('Version constraint %s is not supported.', $value)
            );
        }

        switch ($value[0]) {
            case '~':
                return $this->handleTildeOperator($value);
            case '^':
                return $this->handleCaretOperator($value);
        }

        $constraint = new VersionConstraintValue($value);

        if ($constraint->getMajor()->isAny()) {
            return new AnyVersionConstraint();
        }

        if ($constraint->getMinor()->isAny()) {

View on GitHub (pinned to 5eeb03f1ee)