phpro / grumphp

A PHP code-quality tool
MIT License
4.12k stars 430 forks source link

"Starting the process failed" when run via a git-commit hook by PHPStorm #946

Closed Synchro closed 2 years ago

Synchro commented 2 years ago
Q A
Version 1.5.0
Bug? yes
New feature? no
Question? no
Documentation? no
Related tickets

I have grumphp configured on a git commit hook, running under PHP 8.0.12. Sometimes it fails with an unhelpful error message:

10:55:06.292: [api] git -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -f -- app/Models/User.php
10:55:06.364: [api] git -c core.quotepath=false -c log.showSignature=false commit -F /private/var/folders/nb/4ljl1n1x43941385jnz3qz0m0000gp/T/git-commit-msg-.txt --
GrumPHP detected a pre-commit command.
GrumPHP is sniffing your code!
Running tasks with priority 0!
==============================
Running task 1/1: git_blacklist... 
Running task 1/1: git_blacklist... ✘
git_blacklist
=============
Starting the process failed
To skip commit checks, add -n or --no-verify flag to commit command

My configuration

grumphp:
    fixer:
        enabled: true
        fix_by_default: true
    tasks:
        git_blacklist:
            keywords:
                - "die("
#                - "dump("
                - "dd("
                - "var_dump("
                - "exit;"
            whitelist_patterns: []
            triggered_by: ['php']
            regexp_type: G
            match_word: true
    ascii:
        failed: ~

This appears to be a problem with the way that grumphp is run by PHPStorm. If I run ./vendor/bin/grumphp run or ./vendor/bin/grumphp git:pre-commit from a shell, the commands run successfully (and no problems are found).

Similarly, if I run a simple git commit -a -m "message", grumphp runs successfully.

Because there is no information about why "Starting the process failed", I'm at a loss as to where the problem lies. grumphp is clearly being triggered successfully, but seems to fail for some internal reason.

I also note that this seems to be intermittent, and I can't see a pattern. The particular case that's triggering it for me now is a simple copy change inside a quoted string, changing an O to Ø, so perhaps there are charset environment issues?

veewee commented 2 years ago

Hello @Synchro,

That is strange indeed. I assume you are talking about committing through the user interface inside Phpstorm? Can you share me some details about your operating system?

The error you get is comping from the amp/parallel package: https://github.com/amphp/parallel/blob/master/lib/Context/Process.php#L202

This package is being used for running the tasks in parallel. If you disable parallel execution, you won't get the error anymore:

grumphp:
    parallel:
        enabled: false

Now this isn't really a solution for your problem. As you can see in the linked amp codebase, the excpetion encapsulates the real exception. You might get more information about WHY the process failed to start if you configure AMP_DEBUG=true in your env.

grumphp:
    environment:
      variables:
        AMP_DEBUG: "true"

I have a suspicion that Phpstorm might be using some other or internal binaries instead of the once you are using in your terminal.

Can you add some more feedback based on the information above, so that we can find out the source of the issue? Thanks for reporting!

Synchro commented 2 years ago

Thanks for the advice. I've enabled debug output so I'll see how it goes and let you know if I see anything interesting. I'm running latest EAP builds of PHPStorm 2021.3, and PHP 8.0.12 installed from homebrew on macOS 11.6.

veewee commented 2 years ago

Were you able to inspect the issue a bit more @Synchro ?

Synchro commented 2 years ago

Thanks for following up. I don't know why – though I have upgraded all of macOS, PHP, and PHPStorm since creating this issue – but the problem seems to have gone away by itself, and nothing interesting was logged. One of the mysteries of the universe I guess!

veewee commented 2 years ago

Thanks for clearing this out! Glad it works for you now. :)