squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.67k stars 1.48k forks source link

Catch and show informative error message for out of memory errors #3621

Closed jrfnl closed 2 years ago

jrfnl commented 2 years ago

Depending on the size of a code base, the amount of sniffs run and the memory_limit set for PHP, PHPCS can run out of memory.

Depending on the point at which it runs out of memory, it may show the PHP native "out of memory" error or it may exit without any further information (seen that a number of times as well).

Catching out of memory errors and displaying a user-friendly error message isn't straight-forward, as one can't allocate anymore memory in PHP by that time.

However, my friend @schlessera has worked out a way to do it for another CLI tool and shared the code with me.

@gsherwood Would you be interested in me implementing a user friendly error message for out of memory errors for PHPCS ?

gsherwood commented 2 years ago

I'm not against adding this kind of protection for OOM errors. I haven't seen PHPCS run out of memory without an error, but I'm sure it happens.