phar-io/version · error · NoPreReleaseSuffixException
No pre-release suffix set
Error message
No pre-release suffix set
What it means
NoPreReleaseSuffixException is thrown by Version::getPreReleaseSuffix when the version was parsed from a string without a pre-release part (e.g. '1.2.3'), so $this->preReleaseSuffix is null. The getter has a non-nullable return type, so instead of returning null it throws. Callers must check hasPreReleaseSuffix() first.
Solutions
- Call $version->hasPreReleaseSuffix() before getPreReleaseSuffix().
- Wrap the call in try/catch for NoPreReleaseSuffixException and treat absence as 'stable'.
- If the suffix is genuinely required, validate the input version string contains a '-' pre-release section before constructing.
Example fix
// before $suffix = $version->getPreReleaseSuffix(); // after $suffix = $version->hasPreReleaseSuffix() ? $version->getPreReleaseSuffix() : null;
Defensive patterns
Strategy: type-guard
Validate before calling
// PHP
if (strpos($versionString, '-') === false) {
// no pre-release section; skip suffix handling
} Type guard
function getSuffixOrNull(\Composer\Semver\Version $v): ?\Composer\Semver\PreReleaseSuffix {
return $v->hasPreReleaseSuffix() ? $v->getPreReleaseSuffix() : null;
} Try / catch
try {
$suffix = $version->getPreReleaseSuffix();
} catch (NoPreReleaseSuffixException $e) {
$suffix = null; // stable release
} Prevention
- Always call hasPreReleaseSuffix() before getPreReleaseSuffix().
- Treat missing suffix as a stable release in formatting/logging code.
- Never assume a Version parsed from arbitrary input has a pre-release part.
When it happens
Trigger: Calling $version->getPreReleaseSuffix() on a Version constructed from '1.2.3' or '1.2.3+build'; comparing versions with isGreaterThan is safe internally, but direct getter calls on stable versions throw.
Common situations: Formatting a version string for output by unconditionally calling getPreReleaseSuffix; logging code that assumes every version has a pre-release; tests that parse a plain stable version and then query the suffix.
Related errors
- No build metadata set
- Invalid label
- Version string ' ' does not follow SemVer semantics
- Version constraint is not supported.
AI-assisted analysis of phar-io/version@5eeb03f1ee (2026-09-14).
Data as JSON: /api/errors/72e2485d1a2068b3.
Report an issue: GitHub.
Appendix: source
Thrown at src/Version.php:41
private $patch;
/** @var null|PreReleaseSuffix */
private $preReleaseSuffix;
/** @var null|BuildMetaData */
private $buildMetadata;
public function __construct(string $versionString) {
$this->ensureVersionStringIsValid($versionString);
$this->originalVersionString = $versionString;
}
/**
* @throws NoPreReleaseSuffixException
*/
public function getPreReleaseSuffix(): PreReleaseSuffix {
if ($this->preReleaseSuffix === null) {
throw new NoPreReleaseSuffixException('No pre-release suffix set');
}
return $this->preReleaseSuffix;
}
public function getOriginalString(): string {
return $this->originalVersionString;
}
public function getVersionString(): string {
$str = \sprintf(
'%d.%d.%d',
$this->getMajor()->getValue() ?? 0,
$this->getMinor()->getValue() ?? 0,
$this->getPatch()->getValue() ?? 0
);
if (!$this->hasPreReleaseSuffix()) {View on GitHub (pinned to 5eeb03f1ee)