Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying Patches Drupal8: [ErrorException] Array to string conversion #123

Closed
jiisuominen opened this issue May 2, 2017 · 17 comments
Closed

Comments

@jiisuominen
Copy link

I just updated core to 8.3.1 and updated modules and everything and ran composer update multiple times to get all things updated.

Then after few updates, I started to get this error.

Exception trace:
 () at /var/www/drupalvm/vendor/cweagans/composer-patches/src/Patches.php:296
 Composer\Util\ErrorHandler::handle() at /var/www/drupalvm/vendor/cweagans/composer-patches/src/Patches.php:296
 cweagans\Composer\Patches->postInstall() at n/a:n/a
 call_user_func() at phar:///usr/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:171
 Composer\EventDispatcher\EventDispatcher->doDispatch() at phar:///usr/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:116
 Composer\EventDispatcher\EventDispatcher->dispatchPackageEvent() at phar:///usr/bin/composer/src/Composer/Installer.php:605
 Composer\Installer->doInstall() at phar:///usr/bin/composer/src/Composer/Installer.php:223
 Composer\Installer->run() at phar:///usr/bin/composer/src/Composer/Command/UpdateCommand.php:158
 Composer\Command\UpdateCommand->execute() at phar:///usr/bin/composer/vendor/symfony/console/Command/Command.php:267
 Symfony\Component\Console\Command\Command->run() at phar:///usr/bin/composer/vendor/symfony/console/Application.php:846
 Symfony\Component\Console\Application->doRunCommand() at phar:///usr/bin/composer/vendor/symfony/console/Application.php:191
 Symfony\Component\Console\Application->doRun() at phar:///usr/bin/composer/src/Composer/Console/Application.php:227
 Composer\Console\Application->doRun() at phar:///usr/bin/composer/vendor/symfony/console/Application.php:122
 Symfony\Component\Console\Application->run() at phar:///usr/bin/composer/src/Composer/Console/Application.php:100
 Composer\Console\Application->run() at phar:///usr/bin/composer/bin/composer:54
 require() at /usr/bin/composer:24

I then added some debugging print_r's to Patches.php.

I printed content of that $url variable inside the patching loop @ line 288 of Patches.php.

And this is what I got:

Array
(
    [0] => https://www.drupal.org/files/issues/core_path-alias_manager-language_fallback_and_test-2802403-45-D8.patch
    [1] => https://www.drupal.org/files/issues/core_path-alias_manager-language_fallback_and_test-2802403-45-D8.patch
)

It seems that those patches do get parsed twice, it doesn't matter what files I try to patch, the result is always the same.

Any idea on what might be causing this behavior?

Here's my composer.json with some privacy edits.

{
    "name": "drupal-composer/drupal-project",
    "description": "Project template for Drupal 8 projects with composer",
    "type": "project",
    "license": "GPL-2.0+",
    "authors": [
        {
            "name": "",
            "role": ""
        }
    ],
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        },
        {
            "type": "vcs",
            "url": "git@bitbucket.org:XXX/XXXX"
        }
    ],
    "require": {
        "composer/installers": "^1.2",
        "drupal-composer/drupal-scaffold": "^2.2",
        "cweagans/composer-patches": "~1.0",
        "drupal/core": "~8.0",
        "drush/drush": "~8.0",
        "drupal/console": "~1.0",
        "drupal/admin_toolbar": "^1.0",
        "drupal/better_normalizers": "dev-1.x",
        "drupal/blazy": "^1.0",
        "drupal/breakpoint_js_settings": "^1.0",
        "drupal/config_update": "^1.0",
        "drupal/crop": "1.2",
        "drupal/ctools": "^3.0",
        "drupal/dropzonejs": "1.0-alpha6",
        "drupal/entity": "^1.0",
        "drupal/entity_browser": "1.0-rc2",
        "drupal/entity_reference_revisions": "^1.0",
        "drupal/field_group": "^1.0",
        "drupal/focal_point": "^1.0",
        "drupal/google_analytics": "^2.0",
        "drupal/inline_entity_form": "^1.0",
        "drupal/libraries": "dev-3.x",
        "drupal/linkit": "4.1",
        "drupal/media_entity": "1.6",
        "drupal/media_entity_instagram": "1.2",
        "drupal/media_entity_image": "^1.0",
        "drupal/media_entity_slideshow": "^1.0",
        "drupal/media_entity_twitter": "^1.0",
        "drupal/media_expire": "^1.0",
        "drupal/metatag": "1.x-dev",
        "drupal/paragraphs": "1.0",
        "drupal/pathauto": "^1.0@RC",
        "drupal/scheduler": "^1.0",
        "drupal/simple_sitemap": "2.x-dev",
        "drupal/slick": "^1.0",
        "drupal/slick_media": "^1.0",
        "drupal/token": "^1.0",
        "drupal/video_embed_field": "^1.0",
        "drupal/views_load_more": "dev-1.x",
        "drupal/coffee": "^1.0@beta",
        "zurb/foundation": "^6.3",
        "drupal/module_filter": "^3.0",
        "drupal/ckeditor_media_embed": "^1.0",
        "drupal/ckeditor_font": "^1.0",
        "drupal/search_api": "^1.0@beta",
        "drupal/entity_embed": "^1.0@beta",
        "drupal/file_browser": "^1.0@alpha",
        "drupal/devel": "^1.0@RC",
        "drupal/iframe": "^1.6",
        "drupal/shield": "^1.0",
        "mekanismi/ckeditor_responsive_foundation": "dev-master",
        "drush/config-extra": "^1.0",
        "drupal/fpa": "2.x-dev",
        "drupal/adminimal_theme": "^1.3",
        "drupal/twig_xdebug": "^1.0",
        "drupal/menu_block_current_language": "^1.0@RC",
        "drupal/viewsreference": "^1.0@alpha",
        "ajgl/breakpoint-twig-extension": "^0.3.0",
        "drupal/google_tag": "1.x-dev",
        "drupal/rules": "3.x-dev",
        "drupal/contact_block": "^1.3",
        "drupal/contact_storage": "^1.0@beta",
        "drupal/swiftmailer": "^1.0@beta",
        "drupal/filefield_paths": "^1.0@beta",
        "drupal/redirect": "^1.0@alpha",
        "drupal/eu_cookie_compliance": "^1.0@beta",
        "drupal/stage_file_proxy": "^1.0@alpha",
        "drupal/shortcutperrole": "^1.0@RC",
        "drupal/roleassign": "^1.0@alpha",
        "drupal/cacheflush": "^1.0@alpha",
        "drupal/webform": "^5.0@beta",
        "drupal/config_ignore": "2.0-rc2",
        "drupal/config_filter": "1.x-dev",
        "drupal/config_split": "^1.0@beta",
        "drupal/captcha": "^1.0@beta",
        "drupal/webform_views": "5.x-dev",
        "drupal/webform_layout_container": "^1.0",
        "drupal/reroute_email": "^1.0@beta",
        "drupal/mailgun": "1.x-dev",
        "drupal/composer_manager": "^1.0@RC",
        "drupal/hook_post_action": "1.x-dev"
    },
    "require-dev": {
        "behat/mink": "~1.7",
        "behat/mink-goutte-driver": "~1.2",
        "jcalderonzumba/gastonjs": "~1.0.2",
        "jcalderonzumba/mink-phantomjs-driver": "~0.3.1",
        "mikey179/vfsStream": "~1.2",
        "phpunit/phpunit": "~4.8",
        "symfony/css-selector": "~2.8"
    },
    "conflict": {
        "drupal/drupal": "*"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "autoload": {
        "classmap": [
            "scripts/composer/ScriptHandler.php"
        ]
    },
    "scripts": {
        "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",
        "pre-install-cmd": [
            "DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
        ],
        "pre-update-cmd": [
            "DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
        ],
        "post-install-cmd": [
            "DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
        ],
        "post-update-cmd": [
            "DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
        ]
    },
    "extra": {
        "installer-paths": {
            "web/core": ["type:drupal-core"],
            "web/libraries/{$name}": ["type:drupal-library"],
            "web/modules/contrib/{$name}": ["type:drupal-module"],
            "web/profiles/contrib/{$name}": ["type:drupal-profile"],
            "web/themes/contrib/{$name}": ["type:drupal-theme"],
            "drush/contrib/{$name}": ["type:drupal-drush"]
        },
        "patches": {
            "drupal/paragraphs": {
                "IEF Simple Widget not working in paragraphs with preview mode": "https://www.drupal.org/files/issues/ief_simple_widget_not-2722097-36.patch",
                "Saving problem in preview mode with IEF items": "https://www.drupal.org/files/issues/saving_problem_in-2804377-2.patch"
            },
            "drupal/dropzonejs": {
                "DropzneJS is cleared on every Ajax response": "https://www.drupal.org/files/issues/dropznejs_is_cleared_on-2827120-11_0.patch",
                "Improved MultiStep selection display (DropZone Widget)": "https://www.drupal.org/files/issues/improved_multistep-2823670-14.patch"
            },
            "drupal/linkit": {
                "Missing ckeditor plugin schema": "https://www.drupal.org/files/issues/missing_ckeditor_plugin-2812889-2.patch"
            },
            "drupal/media_entity": {
                "Make the label form element non-required in the entity form": "https://www.drupal.org/files/issues/2813685-21.patch"
            },
            "drupal/media_entity_instagram": {
                "Make posts responsive": "https://www.drupal.org/files/issues/make_posts_responsive-2807735-13.patch"
            },
            "drupal/filefield_paths": {
                "Call to undefined method BaseFieldDefinition::getThirdPartySettings()": "https://www.drupal.org/files/issues/ignore_base_fields.patch"
            },
            "drupal/mailgun": {
                "Mailgun api version user configurable": "https://www.drupal.org/files/issues/configurable_api_version-2865386.patch"
            },
            "drupal/core" : {
                "Link Field Causes Pages to 404 with Bad Route Caching on Multilingual Sites": "https://www.drupal.org/files/issues/core_path-alias_manager-language_fallback_and_test-2802403-45-D8.patch"
            },
            "drupal/crop": {
                "Crop-modulen installDefaultConfig pois": "https://bitbucket.org/!api/2.0/xxxxx/xxxx.patch"
            }
        }
    }
}

I think I was updating Paragraphs to 1.1, Entity Browser to 1.0, Dropzonejs to 1.0-alpha6 and Linkit to 4.3 if that has anything to do with anything.

Thanks for any assistance, our updates are stuck because of this, so any help is appreciated.

/ Janne

@cweagans
Copy link
Owner

cweagans commented May 2, 2017

I haven't looked into it too far, but my guess is that one of your dependencies is adding the same patch that you're trying to add. Your composer.json finished successfully for me locally, but I had to remove your bitbucket repo and mekanismi/ckeditor_responsive_foundation from the requirements to get it to finish. Consider starting with the composer.json in mekanismi/ckeditor_responsive_foundation to see if it defines the same patch you have in your root composer.json.

@jiisuominen
Copy link
Author

Hey and thanks for quick response!

I'm pretty sure that this is not because of the patches being applied twice. Well they are, but defined only once still. I experimented a little, and found out that if I remove all patches from my composer.json, composer updates as it should. And what ever patch I try to add back, then that patch will throw this error. And ALL other patches that I once had in my composer.json gets applied as well.

For example, I left only that drupal/crop patch, and ran composer update -v and still it tried to apply patches for core that weren't even present in composer.json.

Package operations: 9 installs, 0 updates, 0 removals
Installs: drupal/core:8.3.1, drupal/crop:1.2.0, drupal/dropzonejs:1.0.0-alpha6, drupal/linkit:4.1.0, drupal/media_entity:1.6.0, drupal/media_entity_instagram:1.2.0, drupal/paragraphs:1.0.0, drupal/filefield_paths:1.0.0-beta1, drupal/mailgun:dev-1.x eaafb75
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
Found 1 patches for drupal/crop.
Found 2 patches for drupal/paragraphs.
Found 2 patches for drupal/dropzonejs.
Found 1 patches for drupal/linkit.
Found 1 patches for drupal/media_entity.
Found 1 patches for drupal/media_entity_instagram.
Found 1 patches for drupal/filefield_paths.
Found 1 patches for drupal/mailgun.
Found 2 patches for drupal/core.
  - Installing drupal/core (8.3.1): Loading from cache Extracting archive
  - Applying patches for drupal/core
    https://www.drupal.org/files/issues/2828438-22.patch (Exception when adding tab to a node managed by content moderation)
cd 'web/core' && git --git-dir=. apply --check '-p1' '/tmp/590969ef22e96.patch'
error: core/modules/content_moderation/src/Plugin/Menu/EditTab.php: No such file or directory
...

And here's my patches section from composer.json:

        "patches": {
            "drupal/crop": {
                "Crop-modulen installDefaultConfig pois": "https://bitbucket.org/!api/2.0/snippets/...../config_installer_pois.patch"
            }
        }

So I'm starting to think that there's some caching going on that I'm not aware of, or something gets read twice. I'll continue experimenting.

Cheers,

Janne

@jiisuominen
Copy link
Author

Hmm.. I added some code to get past this error on my local drupalvm.
Like so:

      if(is_array($url)){
        print('postInstall');
        print_r($url);
        $url = reset($url);
      }

With this added to 2 methods in Patches.php I got packages updated. Although, those patches are doubled on every patch I try to apply.

I then thought that my local composer / DrupalVM is messed up and tested with our stage environment. Didn't get any errors, but those merged patches that I've removed from my composer.json are still present and composer tries to apply them. So I get quite some errors.

For example:

  - Applying patches for drupal/paragraphs
    https://www.drupal.org/files/issues/ief_simple_widget_not-2722097-36.patch (IEF Simple Widget not working in paragraphs with preview mode)
   Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/ief_simple_widget_not-2722097-36.patch
    https://www.drupal.org/files/issues/saving_problem_in-2804377-2.patch (Saving problem in preview mode with IEF items)
   Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/saving_problem_in-2804377-2.patch

Those patches are definitely NOT in active composer.json.

Everything seems to be working, so I'm not really sure what's happening here.

Cheers,

Janne

@cweagans
Copy link
Owner

cweagans commented May 3, 2017

What if you remove all the patches from your root composer.json, and then set the enable-patching option so that dependency patches are still applied?

@rgristroph
Copy link

I'm posting here to confirm that I am having the same problem. I followed the steps @jiisuominen seems to have done, and ended up at the same place, including observing composer attempting to apply patches that I just removed from the .json file (I had done rm composer.lock and composer clear-cache as well, I'm not sure where it could be remembering that).

I also added this in two places ( lines 289 and 424) in Patches.php:
if (is_array($description)) { $description = $description[0]; } if (is_array($url)) { $url = $url[0]; }`

And that seemed to fix it enough for me to get a .lock file.

rgristroph added a commit to rgristroph/composer-patches that referenced this issue May 5, 2017
@jiisuominen
Copy link
Author

Nice one @rgristroph !

I did some researching and found out that this occurs only if vendor folder exists. If I delete vendor and run composer install, everything works as expected. That's why it worked on our deployments, even if we couldn't run install locally.

Is there any way for me to patch this plugin automatically? Or do I have to setup separate repo for this fix?

Cheers,
Janne

@cweagans
Copy link
Owner

cweagans commented May 9, 2017

Please open a pull request.

@rgristroph
Copy link

rgristroph commented May 9, 2017

@cweagans I opened a PR here: #124 As I note there, it's not a final fix, just a temporary hack. I might be able to dig into this more later this week though.

@jiisuominen If you want to use my hack-patch to get things working temporarily, in your composer.json, in the "repositories" list, add an entry like this:

"1": {
      "type": "vcs",
      "url": "https://github.com/rgristroph/composer-patches"
}

Then, in the "require" section, make the line

"cweagans/composer-patches": "1.6.1.1",

However keep in mind that I don't intend to maintain that repo, and all updates in this official repo. This is only useful for getting through a build process right now until there's a real fix. If you have to do this make a reminder or put a story in your next sprint to clean it up.

@BramG
Copy link

BramG commented Jun 12, 2017

I have the same error but only on our build servers which don't have a vendor dir...

@sridharmula
Copy link

Hi, do we have any final fix or update for this issue? still having the issue.

@rgristroph
Copy link

Hi all, my project seems to be not having this issue any more. It might be related to updating to Drupal 8.3.4. In any case, one of my co-workers tested removing the patch listed in my comment above, and we are not seeing the error any more.

That makes it hard to figure out a better patch than the one I did.

@sridharmula , @BramG , @jiisuominen -- are you folks still seeing these errors after Drupal 8.3.4 ?

@jiisuominen
Copy link
Author

@rgristroph just updated to 8.3.4 and at least one removed patch wants to get applied, even if it's not present in composer.json.

I will need to test more, but to this project I never used your patched version.

@LionsAd
Copy link
Contributor

LionsAd commented Jul 14, 2017

I could reproduce the error.

In my case a ctools patch failed to apply and then ctools had all the patches of all projects stored in installed.json.

Not sure it was due to the failed thing, but the extra section definitely was wrong.

AH.

Yes, it is the wrong thing:

        $this->io->write('   <error>Could not apply patch! Skipping. The error was: ' . $e->getMessage() . '</error>');

// THIS IS WRONG! ---- HAH!
        $extra = $this->composer->getPackage()->getExtra();

        if (getenv('COMPOSER_EXIT_ON_PATCH_FAILURE') || !empty($extra['composer-exit-on-patch-failure'])) {
          throw new \Exception("Cannot apply patch $description ($url)!");
        }

The above line marked is wrong, it should be:

    $extra = $localPackage->getExtra();

because the above line would put the root's patches section into the extra thingy here, which is what happens.

but even more clean would be to leave $extra alone and just have a variable for patches applied.

On the other hand this is also wrong as the exception means this patch was not applied, but others are, so that its correct it should just not do this.

And that also solves my other issue.

@LionsAd
Copy link
Contributor

LionsAd commented Jul 14, 2017

@citlacom
Copy link

Hi guys on last release 1.6.4 I have experimented this issue and happened when in project composer.json file I have declared a patch that also was declared in a dependency composer.json file. There was two same patch covered by a Drupal contrib module in it composer.json file which we previously declared on our main project composer.json file and when that happened this error display and cannot apply any patch.

I just quick solved by removing our main project composer.json file patches declaration and keep the contrib modules lines which will end in the patched modules we expect. Maybe there is a way to handle this more smoothly but I don't know enough of composer-patches source code so leave this report for your evaluation.

Thanks for your help.

@enzolutions
Copy link

Same behavior as @citlacom

@syzygy333
Copy link

I ran into this and had to do things in a specific order for it to work without issue:

  • remove the patch from composer.json
  • composer update --lock to make sure the patch is removed
  • then update the module that I was trying to update

Previously I did the module update first and then removed the patch and instead of the patch being removed from the composer.lock, it listed all the patches for every module, resulting in the error

pczerkas added a commit to pczerkas/composer-patches that referenced this issue Jul 4, 2022
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

No branches or pull requests

9 participants