Skip to content

PHPStan Pro: survive unreadable watched files, watch current config, report worker failures - #6935

Merged
ondrejmirtes merged 4 commits into
2.3.xfrom
pro-fixes
Nov 4, 2026
Merged

ondrejmirtes merged 4 commits into
2.3.xfrom
pro-fixes

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

Fixes for PHPStan Pro's long-running process, found by new visual tests in phpstan/phpstan-fixer#298.

  • A watched file that cannot be read is missing, not fatal. Deleting phpstan.neon for a moment, a baseline removed by git checkout, or a dangling symlink threw CouldNotReadFileException from the FileMonitor timer and shut down all of PHPStan Pro.
  • Watch the config files of the current config. The worker re-reads the config since f519a2f, but the FileMonitor kept watching the files from the startup config. The worker now sends watchedConfigFiles and FixerApplication passes them to the monitor, so config files included after the start are watched.
  • Report a failed analysis instead of waiting forever. An exception in the worker's connect callback became an unhandled rejection: the worker never exited, processInProgress stayed set and file monitoring stopped for good. It is now reported as analysisCrash followed by analysisEnd.
  • Show what is wrong with ignoreErrors edited since the start. An entry without a message or identifier was reported as just "Internal error."; now the real message is shown.

Each change has a phpstan-fixer visual test that fails without it (file-changes.spec.ts: config file missing for a moment, config file included after the start, scanned file that cannot be read, invalid entry in ignoreErrors).

The file monitor hashed every watched file and threw when one could not be
read. A config file, baseline or bootstrap file missing for a moment, like
during a git checkout, ended PHPStan Pro.

Such a file is now missing: deleted while it is gone and new once it is back.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1a31a-13cc-766a-8581-5c4eb5a12a01
The file monitor watched the config files PHPStan Pro started with. A file
included since then, like a newly generated baseline, was read by every
analysis, but its changes were not noticed and nothing was analysed again.

Each fixer:worker reads the config again and now tells FixerApplication its
config files, which the file monitor watches from then on.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1a31a-13cc-766a-8581-5c4eb5a12a01
An exception in the fixer:worker, like a scanned file that cannot be read,
rejected a promise nobody handled. The worker kept its connection open and
waited forever, the UI showed an analysis in progress, and FixerApplication
did not analyse any later change until PHPStan Pro was restarted.

The worker now reports the exception as an internal error and ends the
analysis.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1a31a-13cc-766a-8581-5c4eb5a12a01
FixerApplication validated the ignoreErrors of the config PHPStan Pro started
with. For an invalid entry added later, the fixer:worker threw a bare
ShouldNotHappenException and the UI showed "Analysis crashed" with
"Internal error."

The worker now reports the same messages the analyse command shows, like
"Ignored error ... is missing a message or an identifier."

Amp-Thread-ID: https://ampcode.com/threads/T-01a1a31a-13cc-766a-8581-5c4eb5a12a01
@ondrejmirtes
ondrejmirtes merged commit 06736a0 into 2.3.x Nov 4, 2026
348 of 349 checks passed
@ondrejmirtes
ondrejmirtes deleted the pro-fixes branch November 4, 2026 03:23
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.

1 participant