Currently when a library's version cannot be determined, the following error message is provided:

'The version of the %library library could not be detected.'

There are two reasons a version could not be determined:

  1. The file specified to contain the version information is not present.
  2. The pattern to find the file information did not produce a match.

Knowing which case caused the failure can help end users debug their library dependency issues.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jessebeach’s picture

This patch provides error messages for the two cases stated in the issue summary.

jessebeach’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: failed-version-detection-error-messages-2167249-1.patch, failed testing.

The last submitted patch, 1: failed-version-detection-error-messages-2167249-1.patch, failed testing.

jessebeach’s picture

Status: Needs work » Needs review
Issue tags: +sprint
FileSize
6.48 KB
3.32 KB

Fixed the failing tests.

gobinathm’s picture

Status: Needs review » Reviewed & tested by the community

Fix works

tstoeckler’s picture

Title: Provide more specific error messages when version determination fails » Make version/variant callbacks provide error messages themselves for better DX/UX.
Version: 7.x-2.x-dev » 7.x-3.x-dev
Status: Reviewed & tested by the community » Needs review
FileSize
3.95 KB
7.49 KB

Due to libraries_get_version() taking $library by reference with this patch, this is an API change. Other version callbacks might call libraries_get_version() in a way that is incompatible with references. Therefore (sadly...) moving this to 7.x-3.x

Here's an updated patch. I brought back the fallback error message in order to be sort of backwards-compatible but at that point I hadn't realized the above yet. Therefore we might not actually want that. However, we should allow the same behavior for variant callbacks, so this needs work on that either way. Also re-titling for that.

The inderdiff is with -w so don't try to apply it.

Wim Leers’s picture

Issue tags: -sprint
Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The 5 year old patch in #7 does not apply to the latest libraries 7.x-2.x-dev and if still applicable needs a reroll.

Checking patch libraries.module...
error: while searching for:
    else {
      $library['version'] = $library['version callback']($library, $library['version arguments']);
    }
    if (empty($library['version'])) {
      $library['error'] = 'not detected';
      $library['error message'] = t('The version of the %library library could not be detected.', array(
        '%library' => $library['name'],

error: patch failed: libraries.module:531
error: libraries.module: patch does not apply
Checking patch tests/libraries.test...
error: tests/libraries.test: No such file or directory
Checking patch tests/modules/libraries_test_module/libraries_test_module.module...
error: while searching for:
    'name' => 'Example missing',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/missing',
  );
  $libraries['example_undetected_version'] = array(
    'name' => 'Example undetected version',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version callback' => '_libraries_test_module_return_version',
    'version arguments' => array(FALSE),
  );
  $libraries['example_unsupported_version'] = array(
    'name' => 'Example unsupported version',

error: patch failed: tests/modules/libraries_test_module/libraries_test_module.module:20
error: tests/modules/libraries_test_module/libraries_test_module.module: patch does not apply