Skip to content

Include file path and line number in parse error messages#740

Open
lacatoire wants to merge 1 commit intophpDocumentor:7.xfrom
lacatoire:fix/parse-error-source-location
Open

Include file path and line number in parse error messages#740
lacatoire wants to merge 1 commit intophpDocumentor:7.xfrom
lacatoire:fix/parse-error-source-location

Conversation

@lacatoire
Copy link
Copy Markdown
Contributor

Summary

When parsing a PHP file fails, the error now includes the source file path and line number instead of raw php-parser internals.

Before:

PhpParser\Error: Syntax error, unexpected T_STRING on line 42

After:

phpDocumentor\Reflection\Exception: Syntax error in /path/to/file.php on line 42: Syntax error, unexpected T_STRING
  • NodesFactory::create() accepts an optional $filePath parameter
  • Catches PhpParser\Error and re-throws as phpDocumentor\Reflection\Exception with file + line context
  • Factory\File passes the source path automatically
  • Original exception is preserved as $previous for debugging
  • Fully backward-compatible (the new parameter is optional)

Suggested in phpDocumentor/phpDocumentor#4088 (comment) — moving the error enrichment into the reflection library so all consumers benefit.

When NodesFactory encounters a PhpParser\Error, catch it and re-throw
a phpDocumentor\Reflection\Exception that includes the source file path
and line number. This gives consumers actionable error context instead
of raw php-parser internals.

The create() method now accepts an optional $filePath parameter, and
Factory\File passes the source path automatically.
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