Repository navigation
Add TYPEPHP_DEBUG to surface exceptions TypePHP swallows - #144
Merged
rcalicdan merged 2 commits intoDec 3, 2026
Merged
Conversation
89 catch blocks across the transformer, docblock parser and runtime checkers discard the exception to stay fail-open. When one of them fires, a check is skipped or a file is left uninstrumented with no trace of why. Route every one of them through DebugLog::swallowed(), a no-op unless the TYPEPHP_DEBUG environment variable is truthy. When set, the exception class, message, throw site and catch site go to the PHP error log. Default behaviour is unchanged. Catch blocks that rethrow (CallableWrapper) or already report the exception (RunCommand) are left as they are.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
rcalicdan
requested changes
Dec 3, 2026
rcalicdan
left a comment
Member
There was a problem hiding this comment.
Hello, Can you you add // @codeCoverageIgnore comment on the line where the new Code is written like
DebugLog::swallowed($e); // @codeCoverageIgnoreto supress line coverage on that specific line..
The catch blocks only run when TypePHP hits an internal error, so most of them are never reached by the test suite. Mark each call with @codeCoverageIgnore, as requested in review.
Contributor
Author
|
Done in 8d85787: all 89 |
rcalicdan
approved these changes
Dec 3, 2026
rcalicdan
left a comment
Member
There was a problem hiding this comment.
Thank you for this PR, will be merging now.
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.
Reimplements #130 on top of current
main, as requested there after the internal refactoring.Problem
TypePHP stays fail-open by catching
\Throwable(or\ReflectionException) and discarding it in 89 places across the transformer, docblock parser and runtime checkers. When one of them fires, a check is skipped or a file is left uninstrumented, and nothing says why.Change
TypePHP\Internal\Diagnostic\DebugLog::swallowed(\Throwable $e). It is a no-op unless theTYPEPHP_DEBUGenvironment variable is truthy.CallableWrapper) or already report the exception (RunCommand) are unchanged.Config::isDebugEnabled()reads the variable. There is no config file key; this is a diagnostic switch, not project configuration.With
TYPEPHP_DEBUG=1the PHP error log gets one line per swallowed exception:Default behaviour is unchanged.
Notes
ReflectionExceptionfor a function that does not exist, so the log is verbose by design.redact_valuesis not applied to it.Testing
tests/Internal/Diagnostic/DebugLogTest.phpcovers: silent by default, the logged line with throw and catch site, and a source file that does not parse being reported while still returned untouched. Pint, PHPStan and the full Pest suite pass on PHP 8.5.