In #2236553: Config import validation needs to be able to list multiple issues and the messages should be translatable, validation was made able to report on errors.

However, when such errors occur during import, they are correctly gathered by ConfigImportSubscriber::onConfigImporterValidate() using ConfigImporter::logErrors(), but at the end of ConfigImporter::validate(), when all errors are gathered, they are just ignored and a fixed text ConfigImportsException is thrown.

Coders can still get the errors by invoking $configImporter->getErrors(), but administrators, who are the first in line to be confronted with such exceptions, can not access the information.

Therefore, the messages should be added to the exception text to make the exception actually usable.

Comments

fgm’s picture

Status: Active » Needs review
StatusFileSize
new1.2 KB

A naive patch could look like this, although I suspect this won't fly

Status: Needs review » Needs work

The last submitted patch, 1: 2503263-import_validation_errors.patch, failed testing.

cilefen’s picture

@fgm I had the same problem with the Google PHP API. There was more error information being returned but the exception hid them.

+++ b/core/lib/Drupal/Core/Config/ConfigImporter.php
@@ -755,7 +756,7 @@ protected function validate() {
-      if ($collection == StorageInterface::DEFAULT_COLLECTION) {
+      if ($this->configManager->supportsConfigurationEntities($collection)) {

Is this debug code not intended for the patch?

cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new1.27 KB
new883 bytes
cilefen’s picture

+++ b/core/lib/Drupal/Core/Config/ConfigImporter.php
@@ -727,8 +727,10 @@ protected function validate() {
+      $errors = $errors = $this->getErrors();

That needs fixing.

Also, this will result in real test failures. The actual exception output is checked so those will all have to be updated.

fgm’s picture

Some of this looks like a git rebase problem. All the patch is supposed to do is add a sanitized version of the errors to the exception message, nothing more.

But, as you said, the exception text will probably need to be changed in some test. The fails should tell us where.

Status: Needs review » Needs work

The last submitted patch, 4: config_import-2503263-4.patch, failed testing.

fgm’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new4.6 KB

Rerolled, fixed the tests in ConfigImporterTest, and clarified the motivation for this fix : this is about site administrators, not developers.

charginghawk’s picture

Tried unsuccessfully to get the error message, "There were errors validating the config synchronization", to pop up. With "Full Import", I changed various config to invalid values, I imported improperly compressed files, and finally imported an empty file.

'drush config-import' would display errors: "The import failed due for the following reasons: This import is empty and if applied would delete all of your configuration, so has been rejected." The UI gave me nothing though.

I'd say this ticket needs steps to reproduce. Also, rerolling.

tkoleary’s picture

xjm’s picture

Status: Needs review » Postponed (maintainer needs more info)

Postponing on steps to reproduce, thanks!

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jhedstrom’s picture

Status: Postponed (maintainer needs more info) » Needs review
Issue tags: -Needs steps to reproduce +DX (Developer Experience)
StatusFileSize
new10.97 KB

I'm not sure how to produce this via the UI. However, the search api module is currently having this issue in one of it's tests (#2982693: Test failing on main branch) since #2788777: Allow a site-specific profile to be installed from existing config went in and required system.site, so developers can reproduce the steps this way.

This is a re-working of #8 since the test itself has moved (and thus no easy interdiff either). I made the test more explicit in terms of checking for the expected error messages.

Also @steven.winchers should get credit for his work in the duplicate #2852296: ConfigImporter has an obtuse error message.

Status: Needs review » Needs work

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

jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new1.9 KB
new12.87 KB

This fixes the content moderation config importer test.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

This is really helpful when those errors occur, and would be a good improvement.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Adding this to the exception message is a great idea.

Committed c7afa35 and pushed to 8.6.x. Thanks!

The UI lists the errors already but this makes things easier for developers if the exception is thrown but not caught and handled correctly. Here's the code that does that from \Drupal\config\Form\ConfigSync

      catch (ConfigImporterException $e) {
        // There are validation errors.
        $this->messenger()->addError($this->t('The configuration cannot be imported because it failed validation for the following reasons:'));
        foreach ($config_importer->getErrors() as $message) {
          $this->messenger()->addError($message);
        }
      }

  • alexpott committed c7afa35 on 8.6.x
    Issue #2503263 by jhedstrom, fgm, cilefen: Config import validation...
wim leers’s picture

This is such an important improvement for the site builder (and developer) experience!

alexpott’s picture

@Wim Leers I'm going to tentatively remove those tags. The site builder already has this information when they import configuration. This is mostly useful for a developer when writing a test which does a config import and there's a problem.

Status: Fixed » Closed (fixed)

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