{"record":{"id":"eb21dc83beacf4ef","repo":"phar-io/manifest","slug":"e-getmessage","errorCode":null,"errorMessage":"$e->getMessage()","messagePattern":"\\$e->getMessage\\(\\)","errorType":"exception","errorClass":"ManifestDocumentMapperException","httpStatus":null,"severity":"error","filePath":"src/ManifestDocumentMapper.php","lineNumber":37,"sourceCode":"class ManifestDocumentMapper {\n    public function map(ManifestDocument $document): Manifest {\n        try {\n            $contains          = $document->getContainsElement();\n            $type              = $this->mapType($contains);\n            $copyright         = $this->mapCopyright($document->getCopyrightElement());\n            $requirements      = $this->mapRequirements($document->getRequiresElement());\n            $bundledComponents = $this->mapBundledComponents($document);\n\n            return new Manifest(\n                new ApplicationName($contains->getName()),\n                new Version($contains->getVersion()),\n                $type,\n                $copyright,\n                $requirements,\n                $bundledComponents\n            );\n        } catch (Throwable $e) {\n            throw new ManifestDocumentMapperException($e->getMessage(), (int)$e->getCode(), $e);\n        }\n    }\n\n    private function mapType(ContainsElement $contains): Type {\n        switch ($contains->getType()) {\n            case 'application':\n                return Type::application();\n            case 'library':\n                return Type::library();\n            case 'extension':\n                return $this->mapExtension($contains->getExtensionElement());\n        }\n\n        throw new ManifestDocumentMapperException(\n            sprintf('Unsupported type %s', $contains->getType())\n        );\n    }\n","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/phar-io/manifest/blob/c581d4941e196459bf76c945a8ca922963a66708/src/ManifestDocumentMapper.php#L19-L55","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read getMessage() and the previous exception to identify the failing mapping step","Fix the offending value in the manifest XML (type name, version constraint, or application name)","Validate the manifest with ManifestLoader::fromString() during development before shipping","Ensure the phar-io/version package is current so modern constraint syntax parses"],"exampleFix":"// before: catching the generic wrapper\ntry { $m = (new ManifestDocumentMapper())->map($doc); }\ncatch (ManifestDocumentMapperException $e) { /* opaque */ }\n// after: inspect the root cause\ntry { $m = (new ManifestDocumentMapper())->map($doc); }\ncatch (ManifestDocumentMapperException $e) {\n    $root = $e->getPrevious() ?? $e;\n    error_log($root->getMessage());\n}","handlingStrategy":"try-catch","validationCode":"// pre-check the document before mapping\n$root = $dom->documentElement;\n$type = $root->getAttribute('type');\nif (!in_array($type, ['application','library','extension'], true)) {\n    throw new InvalidArgumentException(\"unsupported manifest type: $type\");\n}","typeGuard":"function isManifestDocument($doc): bool { return $doc instanceof \\PharIo\\Manifest\\ManifestDocument; }","tryCatchPattern":"try {\n    $manifest = (new ManifestDocumentMapper())->map($document);\n} catch (ManifestDocumentMapperException $e) {\n    $cause = $e->getPrevious();\n    // log $cause->getMessage() and fix the manifest value it names\n}","preventionTips":["Validate manifest XML against the phar.io manifest schema before mapping","Test manifests with ManifestLoader::fromString() in CI","Keep phar-io/version up to date for current constraint syntax"],"tags":["php","manifest","exception-wrapping","phar"],"backgroundTag":"schema-validation-failed","analyzedSha":"c581d4941e196459bf76c945a8ca922963a66708","analyzedAt":"2026-09-14T11:08:47.165Z","contentChangedAt":"2026-09-14T11:08:47.165Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}