Problem/Motivation

#2208429: Extension System, Part III: ExtensionList, ModuleExtensionList and ProfileExtensionList introduced a bug when called for a non-installed module. It should return an empty array but it throws an exception.

Proposed resolution

Catch the exception and return an empty array.

Remaining tasks

User interface changes

None

API changes

None - fixing a breaking change.

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Mile23’s picture

Thanks, @alexpott.

+++ b/core/modules/system/tests/src/Kernel/System/SystemGetInfoTest.php
@@ -0,0 +1,31 @@
+    $this->assertEquals([], system_get_info('module', 'user'));

Should be assertSame().

alexpott’s picture

Changed to use assertSame() and expanded the test to cover more of system_get_info()'s functionality.

The last submitted patch, 2: 2939904-2.test-only.patch, failed testing. View results

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

This looks like a proper bugfix! Thank you for the detailed test coverage.

+++ b/core/modules/system/system.module
@@ -963,7 +963,12 @@ function system_get_info($type, $name = NULL) {
+      catch (\InvalidArgumentException $e) {
+        return [];
+      }

Just a general comment: Wouldn't it be nice to have a dedicated exception type for this?

Mile23’s picture

Running the test without the changes to system.module I got this, which seems appropriate:

$ ./vendor/bin/phpunit -c core/ --testsuite kernel --filter SystemGetInfoTest
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

Testing 
E

Time: 12.72 seconds, Memory: 38.00MB

There was 1 error:

1) Drupal\Tests\system\Kernel\System\SystemGetInfoTest::testSystemGetInfo
InvalidArgumentException: The module user does not exist or is not installed.

Also it's nice to get coverage for themes.

In #3, I meant that assertSame() was needed for checking against an expected empty array, but changing them all to assertSame() is fine, too. :-)

And.... I can install ajax_example, which was my original issue: #2208429-340: Extension System, Part III: ExtensionList, ModuleExtensionList and ProfileExtensionList

So this LGTM.

Re: #6, we should really deprecate system_get_info() for something else rather than changing its return values.

dawehner’s picture

Most failure in #2659940: Extension System, Part III: ThemeExtensionList and ThemeEngineExtensionList right now are actually triggered and prevented by this patch.

almaudoh’s picture

Most failure in #2659940: Extension System, Part III: ThemeExtensionList right now are actually triggered and prevented by this patch.

I believe this to be the case also. So just waiting for this patch to be committed.

larowlan’s picture

I agree with #6 - can we get a follow up for that?

Adding review credit for @Mile23

  • larowlan committed 38c2ac7 on 8.6.x
    Issue #2939904 by alexpott, Mile23: Fix system_get_info() for non-...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed 38c2ac7 and pushed to 8.6.x.
Thanks!

Mile23’s picture

almaudoh’s picture

I agree with #6 - can we get a follow up for that?

Created #2940203: Use dedicated Exception classes for extension system for that.

Status: Fixed » Closed (fixed)

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