Skip to content

Commit

Permalink
feat: add context to XML parsing errors (#5335)
Browse files Browse the repository at this point in the history
  • Loading branch information
yivi authored Jan 16, 2023
1 parent 10da65f commit a558c94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Metadata/Extractor/XmlResourceExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function extractPath(string $path): void
try {
simplexml_import_dom(XmlUtils::loadFile($path, XmlPropertyExtractor::SCHEMA));
} catch (\InvalidArgumentException) {
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
throw new InvalidArgumentException(sprintf('Error while parsing %s: %s', $path, $e->getMessage()), $e->getCode(), $e);
}

// It's a property: ignore error
Expand Down
5 changes: 4 additions & 1 deletion tests/Metadata/Extractor/XmlExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,10 @@ public function testInvalidXML(string $path, string $error): void
public function getInvalidPaths(): array
{
return [
[__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\./"],
[
__DIR__.'/xml/invalid/required_class.xml',
"/^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\./",
],
];
}
}

0 comments on commit a558c94

Please sign in to comment.