{"record":{"id":"a3e6a5cde33afb15","repo":"sebastianbergmann/phpunit","slug":"cannot-read-baseline-s-s","errorCode":null,"errorMessage":"Cannot read baseline %s: %s","messagePattern":"Cannot read baseline (.+?): (.+?)","errorType":"exception","errorClass":"CannotLoadBaselineException","httpStatus":null,"severity":"error","filePath":"src/Runner/Baseline/Reader.php","lineNumber":51,"sourceCode":"     * @param non-empty-string $baselineFile\n     *\n     * @throws CannotLoadBaselineException\n     */\n    public function read(string $baselineFile): Baseline\n    {\n        if (!is_file($baselineFile)) {\n            throw new CannotLoadBaselineException(\n                sprintf(\n                    'Cannot read baseline %s, file does not exist',\n                    $baselineFile,\n                ),\n            );\n        }\n\n        try {\n            $document = (new XmlLoader)->loadFile($baselineFile);\n        } catch (XmlException $e) {\n            throw new CannotLoadBaselineException(\n                sprintf(\n                    'Cannot read baseline %s: %s',\n                    $baselineFile,\n                    trim($e->getMessage()),\n                ),\n            );\n        }\n\n        $documentElement = $document->documentElement;\n\n        assert($documentElement !== null);\n\n        $version = (int) $documentElement->getAttribute('version');\n\n        if ($version !== Baseline::VERSION) {\n            throw new CannotLoadBaselineException(\n                sprintf(\n                    'Cannot read baseline %s, version %d is not supported',","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Runner/Baseline/Reader.php#L33-L69","documentation":"The baseline file exists but PHPUnit could not parse it as XML: XmlLoader::loadFile() raised an XmlException whose message (libxml error detail) is embedded in this CannotLoadBaselineException. A baseline must be the well-formed XML document that --generate-baseline writes (a <files> root with a version attribute).","triggerScenarios":"Hand-edited baseline with broken tags; file truncated by an interrupted write; merge-conflict markers (<<<<<<<) left in; --baseline pointing at a different XML artifact (e.g. a coverage XML with another root element).","commonSituations":"Git merge conflicts on a shared baseline; scripts appending to the file; encoding corruption; a tool stripping the root element.","solutions":["Validate the file: xmllint --noout .phpunit/baseline.xml and fix what it reports (often conflict markers or a truncated tail).","If unsure, regenerate from scratch: vendor/bin/phpunit --generate-baseline=<path> (overwrites with valid XML).","Confirm --baseline really points at a baseline document, not another XML file."],"exampleFix":"# before\nvendor/bin/phpunit --baseline=.phpunit/baseline.xml  # malformed XML\n\n# after\nxmllint --noout .phpunit/baseline.xml   # fix reported errors, or:\nvendor/bin/phpunit --generate-baseline=.phpunit/baseline.xml","handlingStrategy":"validation","validationCode":"// Validate baseline XML before the run\n$doc = new DOMDocument();\nif (!$doc->load($baselinePath)) {\n    fwrite(STDERR, \"Baseline {$baselinePath} is not well-formed XML\\n\");\n    exit(1);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run xmllint --noout on the baseline in CI to catch corruption from merges.","Never hand-edit baselines; regenerate with --generate-baseline.","Treat merge conflicts in baseline files as a signal to regenerate both sides."],"tags":["phpunit","php","baseline","xml"],"backgroundTag":"baseline-xml-invalid","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}