phar-io/manifest · error · ManifestDocumentException
$t->getMessage()
Error message
$t->getMessage()
What it means
ManifestDocument::fromString wraps any Throwable raised while loading the XML string into a ManifestDocumentException whose message is the underlying exception's message (in PHP, DOMDocument::loadXML emits a warning/notice rather than throwing, so this catch rarely fires; the message is whatever the native DOM/libxml layer threw). It signals that the string could not be turned into a DOMDocument. The library re-throws with code 0 and the original as previous exception.
Solutions
- Print the previous exception via $e->getPrevious() to see the underlying libxml/DOM error
- Verify the input string is non-empty and well-formed XML before calling fromString
- Ensure the file was read successfully (check file_get_contents return value !== false)
- Use fromFile() instead of manually reading then fromString()
Example fix
// before
$doc = ManifestDocument::fromString(file_get_contents($path));
// after
$content = file_get_contents($path);
if ($content === false || trim($content) === '') {
throw new RuntimeException("Manifest file $path unreadable or empty");
}
$doc = ManifestDocument::fromString($content); Defensive patterns
Strategy: try-catch
Validate before calling
if (!is_string($xml) || trim($xml) === '') { throw new InvalidArgumentException('Manifest XML string is empty'); } Type guard
function isNonEmptyString($v): bool { return is_string($v) && trim($v) !== ''; } Try / catch
try { $doc = ManifestDocument::fromString($xml); } catch (ManifestDocumentException $e) { $cause = $e->getPrevious(); log_error($cause ? $cause->getMessage() : $e->getMessage()); } Prevention
- Never pass raw file_get_contents output without checking for false/empty
- Prefer ManifestDocument::fromFile() over manual read + fromString
- Sanity-check the string starts with '<?xml' or '<phar' before parsing
When it happens
Trigger: Calling ManifestDocument::fromString() with input that makes DOMDocument construction/loading throw — e.g. an empty string passed to loadXML, or a PHP level failure inside the try block. Note empty input typically surfaces as libxml errors -> ManifestDocumentLoadingException instead; this catch handles Throwable cases.
Common situations: Passing null/empty output from file_get_contents to fromString because the manifest file path was wrong; feeding non-XML content (HTML, binary, truncated download); encoding problems in the manifest string.
Related errors
- Processing string failed
- Not a phar.io manifest document
- Element missing
- Attribute not set on element
- Element missing
AI-assisted analysis of phar-io/manifest@c581d4941e (2026-09-14).
Data as JSON: /api/errors/e3993bf6adc1bde8.
Report an issue: GitHub.
Appendix: source
Thrown at src/xml/ManifestDocument.php:52
);
}
return self::fromString(
file_get_contents($filename)
);
}
public static function fromString(string $xmlString): ManifestDocument {
$prev = libxml_use_internal_errors(true);
libxml_clear_errors();
try {
$dom = new DOMDocument();
$dom->loadXML($xmlString);
$errors = libxml_get_errors();
libxml_use_internal_errors($prev);
} catch (Throwable $t) {
throw new ManifestDocumentException($t->getMessage(), 0, $t);
}
if (count($errors) !== 0) {
throw new ManifestDocumentLoadingException($errors);
}
return new self($dom);
}
private function __construct(DOMDocument $dom) {
$this->ensureCorrectDocumentType($dom);
$this->dom = $dom;
}
public function getContainsElement(): ContainsElement {
return new ContainsElement(
$this->fetchElementByName('contains')View on GitHub (pinned to c581d4941e)