phar-io/manifest · error · ManifestDocumentException

Element missing

Error message

Element %s missing

What it means

ManifestDocument::fetchElementByName looks up a direct child element by name in the phar.io namespace via getElementsByTagNameNS and throws ManifestDocumentException('Element %s missing') when no DOMElement is found. It backs getContainsElement, getCopyrightElement, getRequiresElement and getBundlesElement, so a top-level required section (contains, copyright, requires, bundles) is absent from the manifest.

Solutions

  1. Add the missing required element (e.g. <requires>) to the manifest XML
  2. Ensure all elements use the phar.io namespace xmlns="https://phar.io/manifest"
  3. Regenerate the manifest with a current version of the build tool
  4. Check which element name appears in the exception message and verify its spelling

Example fix

// before
<phar xmlns="https://phar.io/manifest"><contains>...</contains></phar>
// after
<phar xmlns="https://phar.io/manifest"><contains>...</contains><requires><php version="8.1"/></requires></phar>
Defensive patterns

Strategy: try-catch

Validate before calling

$dom->loadXML($xml); if ($dom->getElementsByTagNameNS('https://phar.io/manifest', 'requires')->length === 0) { throw new RuntimeException('Manifest lacks <requires> element'); }

Type guard

function hasElement(DOMDocument $dom, string $name): bool { return $dom->getElementsByTagNameNS('https://phar.io/manifest', $name)->length > 0; }

Try / catch

try { $requires = $doc->getRequiresElement(); } catch (ManifestDocumentException $e) { log_warning('Manifest section missing: ' . $e->getMessage()); $requires = null; }

Prevention

When it happens

Trigger: Accessing e.g. $doc->getRequiresElement() (or contains/copyright/bundles) on a ManifestDocument whose XML lacks that element under the phar.io namespace.

Common situations: Minimal/incomplete manifests generated by older tool versions missing newer required sections; manifests with elements in the wrong namespace so getElementsByTagNameNS finds nothing; hand-trimmed manifests.

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/2e92fd1dec3c2d44. Report an issue: GitHub.

Appendix: source

Thrown at src/xml/ManifestDocument.php:108

    public function getBundlesElement(): BundlesElement {
        return new BundlesElement(
            $this->fetchElementByName('bundles')
        );
    }

    private function ensureCorrectDocumentType(DOMDocument $dom): void {
        $root = $dom->documentElement;

        if ($root->localName !== 'phar' || $root->namespaceURI !== self::XMLNS) {
            throw new ManifestDocumentException('Not a phar.io manifest document');
        }
    }

    private function fetchElementByName(string $elementName): DOMElement {
        $element = $this->dom->getElementsByTagNameNS(self::XMLNS, $elementName)->item(0);

        if (!$element instanceof DOMElement) {
            throw new ManifestDocumentException(
                sprintf('Element %s missing', $elementName)
            );
        }

        return $element;
    }
}

View on GitHub (pinned to c581d4941e)