phar-io/manifest · error · ManifestLoaderException

Loading failed.

Error message

Loading %s failed.

What it means

ManifestLoader::fromFile() loads and maps a manifest file, and converts any Exception from document loading or mapping into ManifestLoaderException with 'Loading %s failed.' plus the filename. The original cause is preserved as the previous exception.

Solutions

  1. Check file_exists() and is_readable() on the filename before calling fromFile()
  2. Print the previous exception to see whether it is a missing-file, XML, or mapping problem
  3. Pass an absolute path instead of a relative one to avoid working-directory surprises
  4. Verify the phar stream wrapper path when loading manifests inside phar archives

Example fix

// before
$manifest = ManifestLoader::fromFile($path);
// after
if (!is_file($path)) {
    throw new RuntimeException("manifest missing: $path");
}
$manifest = ManifestLoader::fromFile($path);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!is_file($filename) || !is_readable($filename)) {
    throw new RuntimeException("Cannot read manifest at: $filename");
}

Type guard

function manifestFileExists(string $filename): bool { return is_file($filename) && is_readable($filename); }

Try / catch

try {
    $manifest = ManifestLoader::fromFile($filename);
} catch (ManifestLoaderException $e) {
    log_error($e->getMessage() . ' cause: ' . $e->getPrevious()?->getMessage());
}

Prevention

When it happens

Trigger: fromFile('/path/to/manifest.xml') where the file does not exist, is not readable, contains invalid XML, or the manifest content fails mapping (bad type, bad constraints).

Common situations: Wrong path or working directory when reading a bundled manifest; unreadable file permissions; a manifest shipped inside a phar whose stream wrapper path is wrong.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at src/ManifestLoader.php:22

 *
 * Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 */
namespace PharIo\Manifest;

use function sprintf;

class ManifestLoader {
    public static function fromFile(string $filename): Manifest {
        try {
            return (new ManifestDocumentMapper())->map(
                ManifestDocument::fromFile($filename)
            );
        } catch (Exception $e) {
            throw new ManifestLoaderException(
                sprintf('Loading %s failed.', $filename),
                (int)$e->getCode(),
                $e
            );
        }
    }

    public static function fromPhar(string $filename): Manifest {
        return self::fromFile('phar://' . $filename . '/manifest.xml');
    }

    public static function fromString(string $manifest): Manifest {
        try {
            return (new ManifestDocumentMapper())->map(
                ManifestDocument::fromString($manifest)
            );
        } catch (Exception $e) {
            throw new ManifestLoaderException(

View on GitHub (pinned to c581d4941e)