Problem/Motivation

Follow up to #2208429: Extension System, Part III: ExtensionList, ModuleExtensionList and ProfileExtensionList. A lot of the exceptions in the extension system use \IllegalArgumentException which is too generic. More specific exceptions are needed for specific conditions.

Proposed resolution

Add two new exception classes UnknownExtensionException and UninstalledExtensionException in the extension namespace and use as appropriate

Remaining tasks

Patch
Reviews
Commit

User interface changes

None

API changes

Two new Exceptions in the extension system

Data model changes

None

Comments

almaudoh created an issue. See original summary.

almaudoh’s picture

Status: Active » Needs review
StatusFileSize
new11.9 KB

Here goes.

almaudoh’s picture

StatusFileSize
new2.33 KB
new14.23 KB

Fixed the expected exceptions in the tests.

The last submitted patch, 2: 2940203-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 3: 2940203-3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

almaudoh’s picture

Status: Needs work » Needs review
StatusFileSize
new3.91 KB
new16.63 KB

Fixed more tests.

dawehner’s picture

+++ b/core/lib/Drupal/Core/Extension/ExtensionList.php
@@ -227,7 +227,7 @@ public function exists($extension_name) {
+   * @throws \Drupal\Core\Extension\UnknownExtensionException

I think we should add them inside an Exception namespace. We are not consistent with that in core at all, but at least for me, having that additional namespace is helpful to keep things focused.

almaudoh’s picture

Issue summary: View changes
StatusFileSize
new7.04 KB
new17.23 KB

Moved to Exception namespace.

Status: Needs review » Needs work

The last submitted patch, 8: 2940203-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

almaudoh’s picture

Status: Needs work » Needs review
StatusFileSize
new2.3 KB
new17.58 KB

Fixed the test fails and CS issues.

Status: Needs review » Needs work

The last submitted patch, 10: 2940203-10.patch, failed testing. View results

almaudoh’s picture

Status: Needs work » Needs review
StatusFileSize
new3.74 KB
new17.95 KB

More test fails and docs fixes

dawehner’s picture

I went through the patch and the introduction of the additional exceptions totally make sense.

This is amazing work. Do you mind creating a change record documenting the new exception classes we have?

+++ b/core/lib/Drupal/Core/Extension/Exception/UninstalledExtensionException.php
@@ -0,0 +1,8 @@
+class UninstalledExtensionException extends \RuntimeException {}

+++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php
@@ -147,7 +149,7 @@ public function getDefault() {
     if (!isset($list[$name])) {
-      throw new \InvalidArgumentException("$name theme is not installed.");
+      throw new UninstalledExtensionException("$name theme is not installed.");

This is a bit of a BC break. I think we should continue extending from the InvalidArgumentException so existing catch statements continue to work.

dawehner’s picture

Status: Needs review » Needs work
Issue tags: +Needs change record
almaudoh’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record
StatusFileSize
new1.15 KB
new17.96 KB

Fixed #13 and added a change record https://www.drupal.org/node/2941753

dawehner’s picture

+++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php
@@ -147,7 +149,7 @@ public function getDefault() {
   public function setDefault($name) {
     $list = $this->listInfo();
     if (!isset($list[$name])) {
-      throw new \InvalidArgumentException("$name theme is not installed.");
+      throw new UninstalledExtensionException("$name theme is not installed.");
     }

Isn't there a place for modules which could throw the same kind of exception?

borisson_’s picture

I'm not sure how to answer #16, but this patch and the change record look great.

Status: Needs review » Needs work

The last submitted patch, 15: 2940203-15.patch, failed testing. View results

almaudoh’s picture

Status: Needs work » Needs review
StatusFileSize
new17.97 KB

Reroll

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

@borisson_
Yeah not sure what #16 was about.
I gave it another review and really liked it.

almaudoh’s picture

I actually looked through the code again and didn't see anywhere where #16 is applicable in the current codebase.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 19: 2940203-19.patch, failed testing. View results

almaudoh’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 19: 2940203-19.patch, failed testing. View results

Mixologic’s picture

Status: Needs work » Reviewed & tested by the community

Testbot Snafu.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 19: 2940203-19.patch, failed testing. View results

borisson_’s picture

Status: Needs work » Reviewed & tested by the community

This was still a testbot fluke, back to rtbc.

  • catch committed aae672c on 8.6.x
    Issue #2940203 by almaudoh, dawehner: Use dedicated Exception classes...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed aae672c and pushed to 8.6.x. Thanks!

Status: Fixed » Closed (fixed)

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

cilefen’s picture