Skip to content

Commit 2f9de7b

Browse files
committed
Improve error messaging when merged XML is invalid
1 parent 65c71f2 commit 2f9de7b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/internal/Magento/Framework/Config/Reader/Filesystem.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,28 @@ protected function _readFiles($fileList)
161161
);
162162
}
163163
}
164+
164165
if ($this->validationState->isValidationRequired()) {
165166
$errors = [];
166167
if ($configMerger && !$configMerger->validate($this->_schemaFile, $errors)) {
168+
// The merged XML is invalid, but each XML document is
169+
// individually valid. (If they had errors, we've have thrown an
170+
// exception in the loop above.) Let's work out which document
171+
// is causing us a problem.
172+
$configMerger = null;
173+
foreach ($fileList as $key => $content) {
174+
if (!$configMerger) {
175+
$configMerger = $this->_createConfigMerger($this->_domDocumentClass, $content);
176+
} else {
177+
$configMerger->merge($content);
178+
}
179+
180+
if (!$configMerger->validate($this->_schemaFile)) {
181+
array_unshift($errors, "Error in merged XML after reading $key");
182+
break;
183+
}
184+
}
185+
167186
$message = "Invalid Document \n";
168187
throw new \Magento\Framework\Exception\LocalizedException(
169188
new \Magento\Framework\Phrase($message . implode("\n", $errors))

0 commit comments

Comments
 (0)