Throw a descriptive exception when typeString cannot be parsed#407
Conversation
There was a problem hiding this comment.
Pull request overview
Improves resilience and debuggability of configuration parsing by turning typeString parse failures into descriptive config exceptions (instead of bubbling raw ParserException), and by standardizing how config errors are surfaced during factory construction.
Changes:
- Introduce
InvalidConfigExceptionbase +InvalidTypeStringInConfigException, and makeUnsupportedParamTypeInConfigExceptionextend the new base. - Catch
PHPStantype-string parser errors inAllowedConfigFactoryand rethrow with config-specific context + wildcard hinting. - Update several
Disallowed*Factoryclasses to catchInvalidConfigExceptionand wrap intoShouldNotHappenException, plus add tests for invalidtypeStringvalues.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Calls/FunctionCallsInvalidTypeStringConfigTest.php | Adds tests covering invalid typeString (wildcard + non-wildcard) paths. |
| src/Exceptions/InvalidConfigException.php | Adds a common abstract base for invalid-config exceptions. |
| src/Exceptions/InvalidTypeStringInConfigException.php | New exception describing failures to parse typeString. |
| src/Exceptions/UnsupportedParamTypeInConfigException.php | Moves to the new invalid-config exception hierarchy. |
| src/Allowed/AllowedConfigFactory.php | Catches parser failures from TypeStringResolver and rethrows as descriptive config exception (with wildcard hint). |
| src/DisallowedCallFactory.php | Wraps invalid-config exceptions into ShouldNotHappenException with identifier context. |
| src/DisallowedConstantFactory.php | Same wrapping behavior for constant config parsing. |
| src/DisallowedNamespaceFactory.php | Same wrapping behavior for namespace/class config parsing. |
| src/DisallowedKeywordFactory.php | Same wrapping behavior for keyword/control structure config parsing. |
| src/DisallowedSuperglobalFactory.php | Same wrapping behavior for superglobal config parsing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d954504 to
7d5b304
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
A wildcard or other invalid value in `typeString` caused PHPStan to crash at DI container initialisation with a raw `ParserException` and no indication of which config entry was responsible. The new `InvalidTypeStringInConfigException` names the offending `typeString` value, includes the parser's own reason, and appends a wildcard-specific hint when the value contains `*`. Both it and the existing `UnsupportedParamTypeInConfigException` extend the new abstract `InvalidConfigException`, which all factories catch and wrap in `ShouldNotHappenException` with the config identifier prepended.
7d5b304 to
3b2dd42
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
A wildcard or other invalid value in
typeStringcaused PHPStan to crash at DI container initialisation with a rawParserExceptionand no indication of which config entry was responsible.The new
InvalidTypeStringInConfigExceptionnames the offendingtypeStringvalue, includes the parser's own reason, and appends a wildcard-specific hint when the value contains*. Both it and the existingUnsupportedParamTypeInConfigExceptionextend a new abstractInvalidConfigException, which the call, constant, keyword, namespace, and superglobal factories catch and wrap inShouldNotHappenExceptionwith the config identifier prepended.Two tests cover the wildcard and non-wildcard invalid
typeStringpaths, asserting on the full message including the call identifier prefix.