Skip to content

[Issue] feat: more informative error message on xml validation errors #37788

@m2-assistant

Description

@m2-assistant

This issue is automatically created based on existing pull request: #36836: feat: more informative error message on xml validation errors


Description (*)

This PR adds more informative output to the existing error message displayed, when there is invalid XML configuration.

For example if there is invalid layout.xml the standard error message displayed to a developer would be something like:

1 exception(s):
Exception #0 (Magento\Framework\Config\Dom\ValidationException): Element 'arguments': This element is not expected.
Line: 1471

This isn't very helpful as the line number refers to the XML after it has been merged, making it pretty impossible to determine the file that caused the issue.
This PR changes the output to

1 exception(s):
Exception #0 (Magento\Framework\Config\Dom\ValidationException): Element 'arguments': This element is not expected.
Line: 1471
The xml was: 
1466:            <argument name="show_category" xsi:type="boolean">true</argument>
1467:         </arguments>
1468:      </block>
1469:      <referenceBlock name="product_view_detail" remove="true"/>
1470:      <block name="abc.gtm.product_view_detail" class="ABC\GoogleTagManager\Block\Detail" template="ABC_GoogleTagManager::detailproduct.phtml"/>
1471:      <arguments>
1472:         <argument name="show_category" xsi:type="boolean">true</argument>
1473:      </arguments>
1474:   </referenceContainer>
1475:</body>

Which although the line numbers still refer to the merged XML, it will allow the developer to search the source files for a more specific string. Making it much easier to find the source of the issue.

Related Pull Requests

https://github.com/magento-gl/magento2ee/pull/205

Fixed Issues (if relevant)

N/A

Manual testing scenarios (*)

  1. Put the site into development mode, and disable cache.
  2. Add a breaking change to a layout XML file. e.g add: <bar>foo</bar>
  3. Load the frontend of the site,

You should get an error message that you can use to find the offending configuration.

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: UI FrameworkComponent: LoggerIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: doneReported on 2.4.xIndicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions