Skip to content

Throw a descriptive exception when typeString cannot be parsed#407

Merged
spaze merged 1 commit into
mainfrom
spaze/invalid-typestring-exception
Apr 24, 2026
Merged

Throw a descriptive exception when typeString cannot be parsed#407
spaze merged 1 commit into
mainfrom
spaze/invalid-typestring-exception

Conversation

@spaze

@spaze spaze commented Apr 24, 2026

Copy link
Copy Markdown
Owner

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 a new abstract InvalidConfigException, which the call, constant, keyword, namespace, and superglobal factories catch and wrap in ShouldNotHappenException with the config identifier prepended.

Two tests cover the wildcard and non-wildcard invalid typeString paths, asserting on the full message including the call identifier prefix.

@spaze spaze self-assigned this Apr 24, 2026
Copilot AI review requested due to automatic review settings April 24, 2026 16:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 InvalidConfigException base + InvalidTypeStringInConfigException, and make UnsupportedParamTypeInConfigException extend the new base.
  • Catch PHPStan type-string parser errors in AllowedConfigFactory and rethrow with config-specific context + wildcard hinting.
  • Update several Disallowed*Factory classes to catch InvalidConfigException and wrap into ShouldNotHappenException, plus add tests for invalid typeString values.

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.

Comment thread src/DisallowedKeywordFactory.php
Comment thread src/DisallowedCallFactory.php
Comment thread tests/Calls/FunctionCallsInvalidTypeStringConfigTest.php
Comment thread tests/Calls/FunctionCallsInvalidTypeStringConfigTest.php
Comment thread src/DisallowedCallFactory.php
Comment thread src/DisallowedConstantFactory.php
Comment thread src/DisallowedNamespaceFactory.php
Comment thread src/DisallowedSuperglobalFactory.php
@spaze spaze force-pushed the spaze/invalid-typestring-exception branch from d954504 to 7d5b304 Compare April 24, 2026 17:10
@spaze spaze requested a review from Copilot April 24, 2026 17:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/Calls/FunctionCallsInvalidTypeStringConfigTest.php
Comment thread src/Allowed/AllowedConfigFactory.php
Comment thread src/DisallowedPropertyFactory.php
Comment thread src/DisallowedAttributeFactory.php
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.
@spaze spaze force-pushed the spaze/invalid-typestring-exception branch from 7d5b304 to 3b2dd42 Compare April 24, 2026 18:29
@spaze spaze requested a review from Copilot April 24, 2026 18:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/DisallowedPropertyFactory.php
Comment thread src/DisallowedAttributeFactory.php
@spaze spaze merged commit 99894e6 into main Apr 24, 2026
154 checks passed
@spaze spaze deleted the spaze/invalid-typestring-exception branch April 24, 2026 20:03
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