I got a UnsupportedDataTypeConfigException thrown because my config entity was badly formed. But the system log only told me the file where the exception was thrown, and the name of the entity. This leaves the developer having to grep the code for the entity name.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug
Unfrozen changes Unfrozen because it only changes a thrown exception to be more helpful
Prioritized changes The main goal of this issue is DX.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

Status: Active » Needs review
FileSize
970 bytes
jhedstrom’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Makes sense to me. I updated the issue summary to include a beta phase evaluation.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 1: 2267039.drupal.config-exception-file-location.patch, failed testing.

joachim’s picture

Testbot says 'The testbot client is probably malfunctioning.'. Huh.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: 2267039.drupal.config-exception-file-location.patch, failed testing.

joachim’s picture

Status: Needs work » Needs review
FileSize
978 bytes

Rerolled.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +DX (Developer Experience)

Improving our exception, that is great!!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

I like this patch.

We can test that the file is added to the message too. Just add an assertion in ConfigCRUDTest where the exception is tested.

joachim’s picture

Status: Needs work » Needs review
FileSize
1.95 KB

I've added a test of the exception message, but I'm not sure it's going to work.

The patch adds the details to the exception thrown in read(), but in the test it looks like what's being tested is an attempt to write a badly-formed config.

Status: Needs review » Needs work
aerozeppelin’s picture

Status: Needs work » Needs review
FileSize
2.47 KB
3.32 KB

Tests for #11.

Xano’s picture

+++ b/core/modules/config/src/Tests/Storage/FileStorageTest.php
@@ -76,4 +77,18 @@ public function testlistAll() {
+    } catch (UnsupportedDataTypeConfigException $e) {

catch must not be on the same line as the preceding closing curly bracket. Instead it must be on a new line.

Apart from this coding style nitpick, the patch looks RTBC. I confirmed the tests cover the new behavior, and that no existing behavior has changed.

aerozeppelin’s picture

Status: Needs work » Needs review
FileSize
2.47 KB
922 bytes

Changes as per #14.

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Config/FileStorage.php
@@ -95,12 +96,17 @@ public function read($name) {
+      throw new UnsupportedDataTypeConfigException(SafeMarkup::format('Invalid data type in config @name, found in file @file: @message', array(
+        '@name' => $name,
+        '@file' => $filepath,
+        '@message' => $e->getMessage(),
+      )));

SafeMarkup::format() is deprecated and should not be used in exceptions anyway. sprintf() or just plain old string concatenation should be used. Using an escaping method in an exception message can cause double escaping as exception messages are only escaped at the time of output.

aerozeppelin’s picture

Status: Needs work » Needs review
FileSize
2.16 KB
1022 bytes

Changes as per #16.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Nice! This is a really nice improvement

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.1.x and cherry-picked to 8.0.x. Thanks!

  • catch committed 40bf8be on 8.1.x
    Issue #2267039 by aerozeppelin, joachim:...

  • catch committed 1999e1d on
    Issue #2267039 by aerozeppelin, joachim:...

Status: Fixed » Closed (fixed)

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