Skip to content

Commit a558c94

Browse files
authored
feat: add context to XML parsing errors (#5335)
1 parent 10da65f commit a558c94

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Metadata/Extractor/XmlResourceExtractor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function extractPath(string $path): void
5252
try {
5353
simplexml_import_dom(XmlUtils::loadFile($path, XmlPropertyExtractor::SCHEMA));
5454
} catch (\InvalidArgumentException) {
55-
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
55+
throw new InvalidArgumentException(sprintf('Error while parsing %s: %s', $path, $e->getMessage()), $e->getCode(), $e);
5656
}
5757

5858
// It's a property: ignore error

tests/Metadata/Extractor/XmlExtractorTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,10 @@ public function testInvalidXML(string $path, string $error): void
397397
public function getInvalidPaths(): array
398398
{
399399
return [
400-
[__DIR__.'/xml/invalid/required_class.xml', "/^\[ERROR 1868\] Element '\{https:\/\/api-platform\.com\/schema\/metadata\/resources-3\.0\}resource': The attribute 'class' is required but missing\./"],
400+
[
401+
__DIR__.'/xml/invalid/required_class.xml',
402+
"/^Error while parsing .+\/xml\/invalid\/required_class.xml: \[ERROR 1868\] Element '\{https:\/\/api-platform\.com\/schema\/metadata\/resources-3\.0\}resource': The attribute 'class' is required but missing\./",
403+
],
401404
];
402405
}
403406
}

0 commit comments

Comments
 (0)