Skip to main content

composer-patches generic error

This blog post might be outdated!
This blog post was published more than one year ago and might be outdated!
· 2 min read
Stephan Hochdörfer
Head of IT Business Operations

A few weeks ago, whilst applying the latest security patches for Magento, I ran into a problem in our build pipeline. The patches could be applied locally without any issues, but in our build pipeline applying the patches failed.

Like a lot of people, we use the cweagans/composer-patches Composer plugin to apply patches during the Composer install or update lifecycle. The plugin will detect which Composer packages are installed and then patches are available, will apply them.

In our build pipeline, the plugin failed with the very generic error message Cannot apply patch. That led me to believe that something is wrong with the patch file itself. Since I could not figure out what the problem is, I began diving through the source of the plugin. Since the plugin tries to apply the patch with git first, I checked and realized that the git version used in our build container was quite a bit older than my local git version. After making sure that the same git version was used everywhere, the build still failed with the very same error message.

Digging deeper in the source code, I realized that the CLI tool patch is still used as a fallback version when patching via git would fail. So I started the build container locally, connected to it, and wanted to run patch to also make sure the same version of the tool is used. And guess what, the patch tool was not installed at all.

After adding patch as an additional dependency in the Dockerfile of our build container configuration and restarting the build, the pipeline succeeded successful.