Got this message while upgrading v2.0 to v2.1 via drush.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Carlos Miranda Levy’s picture

Getting the same error on all my sites.
Log says:
Warning: Invalid argument supplied for foreach() in libraries_invoke() (line 161 of /home/webappz/drupal7/sites/all/modules/libraries/libraries.module).

Also getting:
Notice: Undefined index: pre-dependencies-load in libraries_invoke() (line 161 of /home/webappz/drupal7/sites/all/modules/libraries/libraries.module).

Have the following modules enabled that require libraries:
Colorbox
Nivo Slider

Both errors are generated for content pages ( node/xxx ), content type (blog, user/blog) and even for instances of image captcha (/image_captcha/xxx/xxxxxxx)

Other than the error message when upgrading and 2 errors for each content access (quickly filling the dblog -- some 60 errors a minute) the site appears to work fine.

Pol’s picture

Assigned: Unassigned » Pol

I'll look into this ASAP.

Pol’s picture

This is weird because the function libraries_info_defaults() adds this 'pre-dependencies-load' => array(), applied here.

I'll keep digging...

Carlos Miranda Levy’s picture

Don't sweat too much over this.
Apparently flushing the caches took care of it.
Not getting the error anymore since flushing all caches.

Pol’s picture

Status: Active » Fixed

Ok, closing the issue, reopen if there are still problem.

hass’s picture

Status: Fixed » Active

The bug is not fixed without a patch.

Pol’s picture

I don't think there is a bug here.
I think this is a problem caused by a wrong cache, that's why flushing it solve the problem.
Beside that, I'm unable to reproduce it at home. Of course, that doesn't mean there is no bug...

Did you succeeded to reproduce it on your side?

philsward’s picture

Clearing the cache using the "admin_menu" module seemed to fix the problem for me as well.

ferrangil’s picture

Yes, clear the cache and the error is gone.

coredumperror’s picture

I think I might know the underlying cause of this. It's on line 302 in libraries.api.php:

      // Called before the library's dependencies are loaded.
      'pre-dependencie-load' => array(
        'mymodule_example_libraries_pre_dependencies_load_callback',
      ),

Notice that the array index has a typo, "dependencie" rather than "dependencies". The code that references this array key, on line 426 and 617 in libraries.module, does not share this typo.

tstoeckler’s picture

Priority: Normal » Critical

We should simply clear the caches in the upgrade path. I didn't think of that.

Pol’s picture

Status: Needs review » Active
FileSize
834 bytes

AFAIK, I don't think that the .api.php file has anything to do with the error, but anyway, good catch, here is the patch for #10.

Pol’s picture

Status: Active » Needs review
boazr’s picture

Status: Active » Needs review

clearing cache did not solve anything here, for me.

[user@host /pathtodrupal/sites/www.example.com]$ drush cc all
Invalid argument supplied for foreach() libraries.module:161                                                            [warning]
WD file: The file permissions could not be set on public://css/menu_icons.css.                                          [error]
'all' cache was cleared in /pathtodrupal#www.example.com                                                    [success]
[user@host /pathtodrupal/sites/www.example.com]$ drush cc all
Invalid argument supplied for foreach() libraries.module:161                                                        [warning]
boazr’s picture

Applying the patch. Did not help as well:

Notice: Undefined index: pre-dependencies-load ב-libraries_invoke() (שורה 161 מ-/pathtodrupal/sites/all/modules/libraries/libraries.module).
Warning: Invalid argument supplied for foreach() ב-libraries_invoke() (שורה 161 מ-/pathtodrupal/sites/all/modules/libraries/libraries.module).
boazr’s picture

Status: Needs review » Fixed

my mistake.
after applying the patch and clearing cache, not getting the warning.

coredumperror’s picture

Status: Fixed » Reviewed & tested by the community

I knew I should have just made that patch file myself. I was lazy, so I want to thank Pol for doing the work for me. :)

Also, it looks like the patch is working for a few people, so I set this issue to RTBC.

katannshaw’s picture

Patch on #12 and clearing cache worked for me as well. Thanks Pol and everyone.

hass’s picture

Status: Reviewed & tested by the community » Needs work

This patch does not fix the notices bug.

Pol’s picture

@Hass: Can you explain how to reproduce the bug please ?

Thanks

tstoeckler’s picture

I don't see how the api.php is related to this either, although the fix does look correct. Haven't debugged this in detail, though, TBH. I hope to get to it soon.

coredumperror’s picture

I think the reason that the patch I suggested fixes this problem is because the patched function is hook_libraries_info(). It was incorrectly defining the pre-dependencies-load key, and thus everything that tried to use that key caused an "undefined index error".

hass’s picture

The patch only fix API documentation, nothing else.

tstoeckler’s picture

#23 is correct. Under no circumstances should the api.php file be loaded on a regular request and hook_libraries_info() should never ever be invoked as an actual hook.

coredumperror’s picture

Huh, I was not aware of that.

Then why the heck did my patch fix the problem? Maybe it kicked the caches around a bit, which cleaned something up?

anavarre’s picture

Just want to report that clearing Drupal caches fixes Notice: Undefined index: pre-dependencies-load in libraries_invoke() here.

bendev’s picture

same issue fixed by clearing cache; thx

revagomes’s picture

Clearing cache worked well to me.
No Warnings nor Notices since flushing all caches.

tstoeckler’s picture

Category: bug » support
Priority: Critical » Normal
Status: Needs work » Fixed

I just tried this out myself and I can reproduce the error when updating the code from 7.x-2.0 to 7.x-2.1. When running update.php, however, those notices disappear. As I had suspected, update.php correctly clears the caches, which is the cause for the notices.

That means that anyone who reported this error did not run update.php, which should be part of the normal procedure when updating modules. :-/

I added a note to the 7.x-2.1 release notes about running update.php

Marking this fixed. If anyone can reproduce this error *after* running update.php please re-open.

I also committed the patch in #12: http://drupalcode.org/project/libraries.git/commit/b7247ea00b94b515cdea5...
Thanks for that, Pol and coredumperror!

Pol’s picture

hass ?

hass’s picture

Category: support » bug
Status: Fixed » Needs work

That means that anyone who reported this error did not run update.php, which should be part of the normal procedure when updating modules. :-/

That is completely incorrect as noted in past. I ran an "drush up" and this clears the caches AFTER the module has been updated. But the warnings are BEFORE the cache clear. You need to make sure that this error does not occur while running "drush up". I have no clue about the root cause.

tstoeckler’s picture

Ahh, that was not clear to me. That makes sense. Don't know where that was noted in the past, but hey... Anyway, sorry for the false accusations.

In theory update.php shouldn't be calling any hooks or anything exactly for this reason so I will have do dig at which point you are able to (try to) load a library in update.php. Can you list the libraries you used or the specific set-up? That would be very helpful, thanks.

tstoeckler’s picture

Title: Invalid argument supplied for foreach() libraries.module:161 » Cached libraries (with corrupt data structure) are being loaded on update.php before the update from 2.0 to 2.1

Also changing title to reflect the actual bug.

hass’s picture

Just from memory, but this is what I have installed, nothing else.

  • colorbox 7.x-2.3
  • ckeditor 7.x-1.12
  • GeSHi Filter 7.x-1.1
dianacastillo’s picture

I just got these errors when I tried to delete a piece of content : (I have run update.php several times )
Notice: Undefined index: pre-dependencies-load in libraries_invoke() (line 161 of C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\pn\sites\all\modules\libraries\libraries.module).
Warning: Invalid argument supplied for foreach() in libraries_invoke() (line 161 of C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\pn\sites\all\modules\libraries\libraries.module).
Notice: Undefined index: pre-dependencies-load in libraries_invoke() (line 161 of C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\pn\sites\all\modules\libraries\libraries.module).
Warning: Invalid argument supplied for foreach() in libraries_invoke() (line 161 of C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\pn\sites\all\modules\libraries\libraries.module).
Warning: require_once(C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\pn/sites/all/modules/ais/ctools/page_manager/plugins/tasks/page.inc): failed to open stream: No such file or directory in menu_execute_active_handler() (line 515 of C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\pn\includes\menu.inc).
Notice: Undefined index: pre-dependencies-load in libraries_invoke() (line 161 of C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\pn\sites\all\modules\libraries\libraries.module).
Warning: Invalid argument supplied for foreach() in libraries_invoke() (line 161 of C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\pn\sites\all\modules\libraries\libraries.module).
Warning: require_once(C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\pn/sites/all/modules/ais/ctools/page_manager/plugins/tasks/page.inc): failed to open stream: No such file or directory in menu_execute_active_handler() (line 515 of C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\pn\includes\menu.inc).
Notice: Undefined index: pre-dependencies-load in libraries_invoke() (line 161 of C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\pn\sites\all\modules\libraries\libraries.module).
Warning: Invalid argument supplied for foreach() in libraries_invoke() (line 161 of C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\pn\sites\all\modules\libraries\libraries.module).

katannshaw’s picture

@dianacastillo: I don't know if these steps will work for you, but they worked for me:

  1. Download the Libraries API 7.x-2.1 from http://drupal.org/project/libraries
  2. Run the patch from #12 *or* open your sites/all/modules/libraries/libraries.api.php file and fix this typo on line 302:
    • Change: 'pre-dependencie-load' => array(
    • To: 'pre-dependencies-load' => array(
  3. Run the update script at http://yoursite/update.php
  4. Clear all caches at Admin > Config > Development > Performance

For me, these steps made the notices go away. Hope it helps.

Pol’s picture

Or even easier, use the dev version of Libraries API.

defconjuan’s picture

If the links and patches above don't help you, read on:

Short version: You may also need the patch by barraponto in comment 7 or 12 on http://drupal.org/node/1908042.

Long version: If you've come across this page when Googling "Notice: Undefined index: pre-dependencies-load in libraries_invoke() (line 161..." error like I have, most people reference (1) fixing a typo contained on line 302 of the libraries.api.php; (2) running Drupal update; and (3) clearing all caches. This fixes it for many people, but not for Panopoly or Kala Theme users. For those users, you need to apply the patch by barraponto in comment 7 or 12 on http://drupal.org/node/1908042, then clear your cache and you'll be good to go.

tstoeckler’s picture

Re #38: Thanks for sharing that! I was not aware of that other issue. That is in fact incorrect usage that should be fixed independently.

For this issue, I still have no concrete steps to reproduce this, which is why this is seemingly going nowhere.

hass’s picture

Beget: running update.php cleares all caches. What i said is still correct and does not go away from itself. I'm not running the theme you linked to.

defconjuan’s picture

You're right hass. Running drush cc all after runing update is not necessary -- you're clearing the cache twice. I do it anyway as I'm pretty sure it doesn't hurt.

The purpose of my post is that if doing the fix and clearing your cache does not fix the issue -- you COULD have a theme-linked issue that's fixed in the thread I linked.

tstoeckler’s picture

Re #40: hass, could you please clarify: From the comments above, I thought the problem was that the cached libraries were being accessed on update.php before the caches were being cleared. If that were the case, the notices would appear until the caches are cleared. Are you saying that the notices stick even after running update.php and clearing the caches? Again, I'm not implying this is not an actual bug, it's just that I cannot in any way reproduce this, so more information would be great.

hass’s picture

First of all - I have no idea what this hook does and when it runs.

I just upgraded the module via drush and got these errors. As I have no idea about the internals of the module I cannot help more than telling how to reproduce this bug. This is 100% reproducible as a lot of others have seen it, too.

tstoeckler’s picture

This is 100% reproducible

Please don't make such biased assumptions they're not getting us any further. I said repeatedly that I was not able to reproduce the issue.

What were the exact steps you took? Just saying "I upgraded with Drush" aren't real steps to reproduce. If you could provide those I might be able to help.

hass’s picture

  1. Install v2.0
  2. Drush up
  3. Error
richardj’s picture

Got the same error while updating the module through Drush, i used: drush pm-update libraries to get from version 2.0 to 2.1,

The error happens indeed before the cache is flushed (which does the drush pm-update function by default). This is the output the terminal gives (path changed for obvious reasons).

Invalid argument supplied for foreach() libraries.module:161 [warning]
'all' cache was cleared in /some/path                                     [success]
No database updates required                                                [success]
Finished performing updates.                                                 [ok]
  • ckeditor
  • colorbox
  • facebook-php-sdk
  • jquery
  • molpay

disclaimer: this project was taken over by us from another dev, so i can't say which ones are actually in use right now.

edit: edited the code to be better readable.
edit2: updated with list of libraries installed

tstoeckler’s picture

For anyone posting here. It would be super helpful to list the exact libraries you are using on the site. Ideally the versions, etc. as well and the modules that are using it.

0mni’s picture

//Rage On
I am very annoyed at the fact that because I can't package the library I need I have to use the Libraries module, but it is causing problems with my module installation, as I predicted but was shot down when I was asking about what I can do to get exempt. Utterly ridiculous especially when I library I want to include is under the same GNU GPL license ....
//Rage Off

I have this problem when I enable my module Omni EVE API every time. https://drupal.org/sandbox/0mni/2043647

Warning: Invalid argument supplied for foreach() in libraries_invoke() (line 161 of /sites/all/modules/libraries/libraries.module).
Notice: Undefined index: installed in libraries_load() (line 621 of /sites/all/modules/libraries/libraries.module).

It is a brand new standard Drupal install, v7.23

Modules I have installed:
Elysia Cron - 7.x-2.1
Email Confirm - 7.x-1.1
Libraries - 7.x-2.1 (I have applied the patch above before enableing for the first time.)
Devel - 7.x-1.3 (Redirect page enabled so I can see the noticies)
Chaos tools - 7.x-1.3
Omni EVE API - My Module I created.

This is in my omni_eve_api.install


/**
 * Implements hook_requirements().
 * 
 * x.x.x.x
 * | | | `-- Patch Version Number.
 * | | |
 * | | `---- 0 = Alpha.
 * | |         1 = Beta.
 * | |         2 = RC.
 * | |         3 = Release.
 * | |
 * | `------ Minor Version Change.
 * |
 * `-------- Major Version Change.
 */
function omni_eve_api_requirements($phase) {
  $requirements = array();
  // Ensure translations don't break during installation.
  $t = get_t();

  // Define the Version Number.
  $oea_version = '1.0.1.1';

  // Report Omni EVE API version.
  if ($phase == 'runtime') {
    $requirements['omni_eve_api'] = array(
      'title' => $t('Omni EVE API'),
      'value' => $oea_version,
      'severity' => REQUIREMENT_INFO,
    );
  }

  if ($phase == 'runtime' || $phase == 'install') {
    $requirements['teamspeak3'] = array(
      'title' => $t('Teamspeak 3 PHP Framework Library'),
    );

    $libraries = libraries_get_libraries();
    if (isset($libraries['TeamSpeak3'])) {
      $path = libraries_get_path('TeamSpeak3');
      if (file_exists($path . '/TeamSpeak3.php')) {
        require_once $path . '/TeamSpeak3.php';
        $teamspeak_version = TeamSpeak3::LIB_VERSION;
        $requirements['teamspeak3']['value'] = $teamspeak_version;
        $requirements['teamspeak3']['severity'] = REQUIREMENT_INFO;
      }
      else {
        $requirements['teamspeak3']['value'] = $t('Not Found');
        $requirements['teamspeak3']['severity'] = REQUIREMENT_ERROR;
        $requirements['teamspeak3']['description'] = $t('The TeamSpeak3.php was not found within the uploaded Teamspeak 3 PHP Framework library. Please verify all files were uploaded correctly.');
      }
    }
    else {
      $requirements['teamspeak3']['value'] = $t('Not Installed');
      $requirements['teamspeak3']['severity'] = REQUIREMENT_ERROR;
      $requirements['teamspeak3']['description'] = $t('Please install the Teamspeak 3 PHP Framework library %url.', array('%url' => 'http://addons.teamspeak.com/directory/tools/integration/TeamSpeak-3-PHP-Framework.html'));
    }
  }

  return $requirements;
}

This is where I load the teamspeak framework, as well where the get_version function exists.

This file is included in omni_eve_api.module
omni_eve_api.ts3.inc

// Load the TeamSpeak 3 PHP Framework Library.
if (($library = libraries_load('TeamSpeak3')) && !empty($library['loaded'])) {
  variable_set('omni_eve_api_ts3_framework_installed', TRUE);
}
else {
  variable_set('omni_eve_api_ts3_framework_installed', FALSE);
  variable_set('omni_eve_api_ts3_enable', FALSE);
}

/**
 * Check the TeamSpeak 3 PHP Framework version.
 *
 * @return string
 *   The version of the TeamSpeak 3 PHP Framework.
 */
function omni_eve_api_teamspeak_get_version() {
  $libraries = libraries_get_libraries();

  if (isset($libraries['TeamSpeak3'])) {
    $path = libraries_get_path('TeamSpeak3');

    if (file_exists($path . '/TeamSpeak3.php')) {
      require_once $path . '/TeamSpeak3.php';
      $teamspeak_version = TeamSpeak3::LIB_VERSION;
      return $teamspeak_version;
    }
    else {
      return '0.0.0';
    }
  }
  else {
    return '0.0.0';
  }
}

This is located in omni_eve_api.module

/**
 * Return information about external libraries.
 *
 * @return array
 *   An associative array whose keys are internal names of libraries and whose
 *   values are describing each library.
 * @see hook_library()
 */
function omni_eve_api_libraries_info() {
  $libraries['TeamSpeak3'] = array(
    'name' => 'Teamspeak 3 PHP Framework Library',
    'vendor url' => 'http://forum.teamspeak.com/showthread.php/54132',
    'download url' => 'http://addons.teamspeak.com/directory/tools/integration/TeamSpeak-3-PHP-Framework.html',
    'version callback' => 'omni_eve_api_teamspeak_get_version',
    'files' => array(
      'php' => array(
        'TeamSpeak3.php',
      ),
    ),
  );

  return $libraries;
}
tstoeckler’s picture

Version: 7.x-2.1 » 7.x-2.x-dev
Status: Needs work » Needs review
FileSize
678 bytes

Instead of carefully trying to reproduce this I decided to roll the following patch.

It would be great if someone could test this.

We can still decide to rip this code back out in 2.4 or whatever, but at this point I'm pretty tired of this issue and could live with this patch.

TravisCarden’s picture

Status: Needs review » Reviewed & tested by the community

I was consistently getting this error after running updb, but after applying the patch in #49 I no longer get it. The change looks like a no-brainer from the diff.

tstoeckler’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

tstoeckler’s picture

The typo fix was never committed to 7.x-3.x so did so now: http://drupalcode.org/project/libraries.git/commit/ec9ddc9e26725550187fc...