Skip to content

Conversation

@CybotTM
Copy link
Contributor

@CybotTM CybotTM commented Dec 8, 2025

Summary

This adds proper XSD schema validation before the configuration is loaded into Symfony's container. When validation fails, users now see precise error messages with line and column numbers instead of cryptic PHP fatal errors.

Before:

PHP Fatal error:  Uncaught Symfony\Component\Config\Definition\Exception\InvalidTypeException: 
Invalid type for path "guides.theme". Expected "scalar", but got "array". in ...
Stack trace:
#0 ...
(20+ lines of stack trace)

After:

 Invalid guides.xml configuration 

Your guides.xml file failed XSD schema validation:

Schema validation failed for Documentation/guides.xml
  Line 3, Column 0: Element '{https://www.phpdoc.org/guides}theme': This element is not expected.

See: https://docs.typo3.org/m/typo3/docs-how-to-document/main/en-us/GeneralConventions/GuideXml.html

Approach

This is a comprehensive fix that:

  • Validates all guides.xml files against the XSD schema upfront
  • Shows exact file path, line number, and column for each error
  • Links to official documentation for correct format
  • Keeps a fallback catch for any edge cases not covered by XSD

Alternative

See also the companion PR with a simpler fix that only catches exceptions without XSD validation: #1117

Test plan

  • Create a malformed guides.xml with <theme name="typo3docs" /> as child element
  • Run bin/guides run --config=Documentation Documentation
  • Verify error message shows exact line number and XSD error
  • Verify valid guides.xml files still render correctly

This adds proper XSD schema validation before the configuration is
loaded into Symfony's container. When validation fails, users now see
precise error messages with line and column numbers instead of
cryptic PHP fatal errors.

Example output for invalid guides.xml:

  Invalid guides.xml configuration

  Your guides.xml file failed XSD schema validation:

  Schema validation failed for Documentation/guides.xml
    Line 3, Column 0: Element 'theme': This element is not expected.

The fix:
- Validates all guides.xml files against the XSD schema upfront
- Shows exact file path, line number, and column for each error
- Links to official documentation for correct format
- Keeps a fallback catch for any edge cases not covered by XSD

This provides much better developer experience compared to the
previous "Expected scalar, but got array" fatal error.
Adds integration tests that verify:
- Invalid guides.xml shows helpful error message instead of PHP Fatal error
- XSD validation error includes line number
- Valid guides.xml files still render successfully
@CybotTM CybotTM force-pushed the fix/validate-guidesxml-before-loading branch from ee20ae6 to 501b733 Compare December 9, 2025 10:05
linawolf pushed a commit that referenced this pull request Dec 11, 2025
…1117)

## Summary

Instead of crashing with a PHP Fatal error when guides.xml contains
invalid configuration, the guides entrypoint now catches
`InvalidTypeException` and `InvalidConfigurationException` and displays
a helpful error message.

**Before:**
```
PHP Fatal error:  Uncaught Symfony\Component\Config\Definition\Exception\InvalidTypeException: 
Invalid type for path "guides.theme". Expected "scalar", but got "array". in ...
Stack trace:
#0 ...
(20+ lines of stack trace)
```

**After:**
```
 Invalid guides.xml configuration 

Your guides.xml file contains a configuration error:
  Invalid type for path "guides.theme". Expected "scalar", but got "array".

Common causes:
  - Invalid or unknown XML element
  - Missing required attributes
  - Invalid attribute values or types

Run vendor/bin/typo3-guides lint-guides-xml for detailed validation.
See: https://docs.typo3.org/m/typo3/docs-how-to-document/main/en-us/GeneralConventions/GuideXml.html
```

## Approach

This is a **minimal fix** that catches exceptions and provides a
user-friendly error message. It's simple (~25 lines) but doesn't provide
line numbers or specific validation details.

## Alternative

See also the companion PR with a **comprehensive fix** that validates
against XSD schema before loading, providing exact line/column numbers:
#1118

## Test plan

- [ ] Create a malformed guides.xml with `<theme name="typo3docs" />` as
child element
- [ ] Run `bin/guides run --config=Documentation Documentation`
- [ ] Verify helpful error message is shown instead of PHP Fatal error
- [ ] Verify valid guides.xml files still render correctly
@linawolf
Copy link
Member

With #1117 we merged the "small variant" of this change, let us see if that is sufficient or we want to merge this, improved variant

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.

2 participants