phar-io/manifest · error · ManifestDocumentMapperException

$e->getMessage()

Error message

$e->getMessage()

What it means

ManifestDocumentMapper::map() wraps any Throwable thrown while converting a ManifestDocument into a Manifest into a ManifestDocumentMapperException, keeping the original message, code, and exception as previous. This is the central catch-all that funnels all mapping failures (bad types, invalid version constraints, invalid names, etc.) into one exception type.

Solutions

  1. Read getMessage() and the previous exception to identify the failing mapping step
  2. Fix the offending value in the manifest XML (type name, version constraint, or application name)
  3. Validate the manifest with ManifestLoader::fromString() during development before shipping
  4. Ensure the phar-io/version package is current so modern constraint syntax parses

Example fix

// before: catching the generic wrapper
try { $m = (new ManifestDocumentMapper())->map($doc); }
catch (ManifestDocumentMapperException $e) { /* opaque */ }
// after: inspect the root cause
try { $m = (new ManifestDocumentMapper())->map($doc); }
catch (ManifestDocumentMapperException $e) {
    $root = $e->getPrevious() ?? $e;
    error_log($root->getMessage());
}
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check the document before mapping
$root = $dom->documentElement;
$type = $root->getAttribute('type');
if (!in_array($type, ['application','library','extension'], true)) {
    throw new InvalidArgumentException("unsupported manifest type: $type");
}

Type guard

function isManifestDocument($doc): bool { return $doc instanceof \PharIo\Manifest\ManifestDocument; }

Try / catch

try {
    $manifest = (new ManifestDocumentMapper())->map($document);
} catch (ManifestDocumentMapperException $e) {
    $cause = $e->getPrevious();
    // log $cause->getMessage() and fix the manifest value it names
}

Prevention

When it happens

Trigger: Calling map() with a document whose contents fail any mapping step: unsupported <contains type>, unparsable php version constraint, unparsable extension compatible constraint, or an <for> name failing ApplicationName validation.

Common situations: Hand-written or tool-generated manifest.xml files with typos, malformed version ranges like '>7.4', or application names missing the vendor/packagename slash format.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of phar-io/manifest@c581d4941e (2026-09-14). Data as JSON: /api/errors/eb21dc83beacf4ef. Report an issue: GitHub.

Appendix: source

Thrown at src/ManifestDocumentMapper.php:37

class ManifestDocumentMapper {
    public function map(ManifestDocument $document): Manifest {
        try {
            $contains          = $document->getContainsElement();
            $type              = $this->mapType($contains);
            $copyright         = $this->mapCopyright($document->getCopyrightElement());
            $requirements      = $this->mapRequirements($document->getRequiresElement());
            $bundledComponents = $this->mapBundledComponents($document);

            return new Manifest(
                new ApplicationName($contains->getName()),
                new Version($contains->getVersion()),
                $type,
                $copyright,
                $requirements,
                $bundledComponents
            );
        } catch (Throwable $e) {
            throw new ManifestDocumentMapperException($e->getMessage(), (int)$e->getCode(), $e);
        }
    }

    private function mapType(ContainsElement $contains): Type {
        switch ($contains->getType()) {
            case 'application':
                return Type::application();
            case 'library':
                return Type::library();
            case 'extension':
                return $this->mapExtension($contains->getExtensionElement());
        }

        throw new ManifestDocumentMapperException(
            sprintf('Unsupported type %s', $contains->getType())
        );
    }

View on GitHub (pinned to c581d4941e)