phar-io/manifest · error · ManifestElementException

Attribute not set on element

Error message

Attribute %s not set on element %s

What it means

ManifestElement::getAttributeValue is the base accessor for all manifest attribute getters (getName, getEmail, getVersion, getType, getFor, getCompatible). When the wrapped DOMElement lacks the requested attribute it throws ManifestElementException('Attribute %s not set on element %s'), naming the attribute and the element's localName.

Solutions

  1. Add the missing attribute named in the message to the element in the manifest XML
  2. Wrap the getter call in try-catch for ManifestElementException
  3. Regenerate the manifest with the current tool version
  4. Validate the manifest against the phar.io XSD before consuming it

Example fix

// before
<author>Sebastian</author>
// after
<author name="Sebastian" email="dev@example.com"/>
Defensive patterns

Strategy: type-guard

Validate before calling

if (!$authorEl->hasAttribute('email')) { throw new RuntimeException('Author element has no email attribute'); }

Type guard

function attributeOrNull(DOMElement $el, string $name): ?string { return $el->hasAttribute($name) ? $el->getAttribute($name) : null; }

Try / catch

try { $email = $author->getEmail(); } catch (ManifestElementException $e) { $email = null; log_warning($e->getMessage()); }

Prevention

When it happens

Trigger: Calling any attribute getter (getName, getEmail, getVersion, getType, getFor, getCompatible) on a manifest element that does not carry the corresponding attribute — e.g. reading ->getAuthorElement()->getEmail() when the <author> element has no email attribute.

Common situations: Hand-edited manifests with omitted optional-looking but required attributes; older manifests generated before an attribute became mandatory; author/vendor elements written without email or url.

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

Appendix: source

Thrown at src/xml/ManifestElement.php:29

namespace PharIo\Manifest;

use DOMElement;
use DOMNodeList;
use function sprintf;

class ManifestElement {
    public const XMLNS = 'https://phar.io/xml/manifest/1.0';

    /** @var DOMElement */
    private $element;

    public function __construct(DOMElement $element) {
        $this->element = $element;
    }

    protected function getAttributeValue(string $name): string {
        if (!$this->element->hasAttribute($name)) {
            throw new ManifestElementException(
                sprintf(
                    'Attribute %s not set on element %s',
                    $name,
                    $this->element->localName
                )
            );
        }

        return $this->element->getAttribute($name);
    }

    protected function hasAttribute(string $name): bool {
        return $this->element->hasAttribute($name);
    }

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

View on GitHub (pinned to c581d4941e)