Non-semver git tag causes PHPStan's internal error when parsing version string#174
Open
mlutonsky wants to merge 5 commits into
Open
Non-semver git tag causes PHPStan's internal error when parsing version string#174mlutonsky wants to merge 5 commits into
mlutonsky wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where non-semver git tags (e.g., 'testing') cause PHPStan internal errors by introducing proper exception handling. When an invalid version string is encountered, it now throws a custom InvalidTagException that is caught and converted to a standard PHPStan error message instead of propagating as an uncaught InvalidVersionString exception.
Key changes:
- Introduced
InvalidTagExceptionfor handling invalid git tags that cannot be parsed as semantic versions - Enhanced
ReferenceVersionFinder::nextVersion()to track the original version string and wrap parsing failures inInvalidTagException - Updated
TodoByVersionRuleto catch and handleInvalidTagExceptionalongside existingLatestTagNotFoundException
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/utils/InvalidTagException.php |
New exception class for invalid tag parsing errors |
src/utils/ReferenceVersionFinder.php |
Added $originalVersionString parameter to track the original tag value through recursive calls, and wraps version parsing failures in InvalidTagException |
src/TodoByVersionRule.php |
Added catch block for InvalidTagException to display user-friendly error messages; also includes minor code style improvements for consistent spacing around concatenation operators |
tests/TodoByVersionRuleTestingTagFetchterTest.php |
New test verifying that invalid tags produce appropriate error messages instead of internal errors |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi and thanks for this awesome phpstan extensions!
This PR fixes bug, when non-semver tag was detected as the latest released tag, causing internal PHPStan error (due to uncaught
\Version\Exception\InvalidVersionStringexception when parsing version string) as:This fix handles the exception, resulting in standard PHPStan error.
... and fixes some tiny codestyle issues.
Thanks.
Cheers!