{"record":{"id":"5a5c4c50c809de0b","repo":"phar-io/manifest","slug":"loading-s-failed","errorCode":null,"errorMessage":"Loading %s failed.","messagePattern":"Loading (.+?) failed\\.","errorType":"exception","errorClass":"ManifestLoaderException","httpStatus":null,"severity":"error","filePath":"src/ManifestLoader.php","lineNumber":22,"sourceCode":" *\n * Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n *\n */\nnamespace PharIo\\Manifest;\n\nuse function sprintf;\n\nclass ManifestLoader {\n    public static function fromFile(string $filename): Manifest {\n        try {\n            return (new ManifestDocumentMapper())->map(\n                ManifestDocument::fromFile($filename)\n            );\n        } catch (Exception $e) {\n            throw new ManifestLoaderException(\n                sprintf('Loading %s failed.', $filename),\n                (int)$e->getCode(),\n                $e\n            );\n        }\n    }\n\n    public static function fromPhar(string $filename): Manifest {\n        return self::fromFile('phar://' . $filename . '/manifest.xml');\n    }\n\n    public static function fromString(string $manifest): Manifest {\n        try {\n            return (new ManifestDocumentMapper())->map(\n                ManifestDocument::fromString($manifest)\n            );\n        } catch (Exception $e) {\n            throw new ManifestLoaderException(","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/phar-io/manifest/blob/c581d4941e196459bf76c945a8ca922963a66708/src/ManifestLoader.php#L4-L40","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Check file_exists() and is_readable() on the filename before calling fromFile()","Print the previous exception to see whether it is a missing-file, XML, or mapping problem","Pass an absolute path instead of a relative one to avoid working-directory surprises","Verify the phar stream wrapper path when loading manifests inside phar archives"],"exampleFix":"// before\n$manifest = ManifestLoader::fromFile($path);\n// after\nif (!is_file($path)) {\n    throw new RuntimeException(\"manifest missing: $path\");\n}\n$manifest = ManifestLoader::fromFile($path);","handlingStrategy":"type-guard","validationCode":"if (!is_file($filename) || !is_readable($filename)) {\n    throw new RuntimeException(\"Cannot read manifest at: $filename\");\n}","typeGuard":"function manifestFileExists(string $filename): bool { return is_file($filename) && is_readable($filename); }","tryCatchPattern":"try {\n    $manifest = ManifestLoader::fromFile($filename);\n} catch (ManifestLoaderException $e) {\n    log_error($e->getMessage() . ' cause: ' . $e->getPrevious()?->getMessage());\n}","preventionTips":["Resolve paths to absolute before loading","Check file existence and readability first","Watch for the fixed generic message — always inspect the previous exception"],"tags":["php","file-loading","manifest","phar"],"backgroundTag":"file-not-found","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"}