Skip to content

feat: add context to XML parsing errors #5335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 16, 2023
Merged

feat: add context to XML parsing errors #5335

merged 6 commits into from
Jan 16, 2023

Conversation

yivi
Copy link
Contributor

@yivi yivi commented Jan 13, 2023

Whenever an XML parsing error is found, the error message will be something like:

[ERROR 1843] Element '{https://api-platform.com/schema/metadata/resources-3.0}operation': Character content other than whitespace is not allowed because the content type is 'element-only'. (in /var/www/ - line 28, column 0) in . (which is being imported from "/var/www/config/routes_api.php"). Make sure there is a loader supporting the "api_platform"
type.

Which is terribly unhelpful. The only file mentioned is in this case is a general routes configuration file, which is absolutely unrelated to the issue at hand.

Yes, ideally one wouldn't be modifying several configuration files at the same time, but sometimes it does happen.

This commit simply adds the path where the error was found to the error message, so now it becomes:

Error while parsing /var/www/src/config/api-platform/SomeResource.xml:
[ERROR 1843] Element '{https://api-platform.com/schema/metadata/resources-3.0}operation': Character content other than whitespace is not allowed because the content type is 'element-only'. (in /var/www/ - line 28, column 0) in . (which is being imported from "/var/www/config/routes_api.php"). Make sure there is a loader supporting the "api_platform" type.

Now the user knows the error happens on SomeResource.xml, and there is less frustration. :)

@yivi yivi closed this Jan 13, 2023
fix code style on XmlResourceExtractor.php
@yivi yivi reopened this Jan 14, 2023
Copy link
Member

@alanpoulain alanpoulain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alanpoulain alanpoulain changed the title Add context to XML parsing errors feat: add context to XML parsing errors Jan 16, 2023
@soyuka
Copy link
Member

soyuka commented Jan 16, 2023

This should target 3.0

@alanpoulain
Copy link
Member

This should target 3.0

Not sure changing a message counts as a bug though.

Copy link
Contributor

@vincentchalamon vincentchalamon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK for targeting main as it's not a bug IMHO

@alanpoulain alanpoulain merged commit a558c94 into api-platform:main Jan 16, 2023
@alanpoulain
Copy link
Member

Thanks @yivi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants