From 34a1deedbba82c4d877bb043a5650a0be14b23ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Elmeris?= Date: Thu, 21 Dec 2017 15:38:27 +0200 Subject: [PATCH 1/6] Display a more meaningful error message in case of misspelt module name. [LogicException] Component 'VendorA_ModuleB' of type '' is not correctly registered. instead of [Magento\Framework\Exception\FileSystemException] The file "/composer.json" doesn't exist --- lib/internal/Magento/Framework/Module/Dir.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/internal/Magento/Framework/Module/Dir.php b/lib/internal/Magento/Framework/Module/Dir.php index 936fce3a046b7..ecd24c5db767a 100644 --- a/lib/internal/Magento/Framework/Module/Dir.php +++ b/lib/internal/Magento/Framework/Module/Dir.php @@ -45,6 +45,10 @@ public function getDir($moduleName, $type = '') { $path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName); + if (! isset($path)) { + throw new \LogicException("Component '$moduleName' of type '$type' is not correctly registered."); + } + if ($type) { if (!in_array($type, [ self::MODULE_ETC_DIR, From 82f701aa68f29964164be618229ddbb49a287ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Elmeris?= Date: Fri, 22 Dec 2017 22:04:12 +0200 Subject: [PATCH 2/6] Do not throw \LogicException, as it would break backwards-compatibility. --- lib/internal/Magento/Framework/Module/Dir.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Module/Dir.php b/lib/internal/Magento/Framework/Module/Dir.php index ecd24c5db767a..47e0836db7f33 100644 --- a/lib/internal/Magento/Framework/Module/Dir.php +++ b/lib/internal/Magento/Framework/Module/Dir.php @@ -45,8 +45,9 @@ public function getDir($moduleName, $type = '') { $path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName); - if (! isset($path)) { - throw new \LogicException("Component '$moduleName' of type '$type' is not correctly registered."); + if (!isset($path)) { + // (Do not throw \LogicException, as it would break backwards-compatibility.) + throw new \InvalidArgumentException("Component '$moduleName' of type '$type' is not correctly registered."); } if ($type) { From 7a0ce57ac06759778f6375bada4b6deba5557b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Elmeris?= Date: Fri, 22 Dec 2017 23:18:20 +0200 Subject: [PATCH 3/6] Allow directory to be not set for non-module types. --- lib/internal/Magento/Framework/Module/Dir.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Module/Dir.php b/lib/internal/Magento/Framework/Module/Dir.php index 47e0836db7f33..309fa33778de4 100644 --- a/lib/internal/Magento/Framework/Module/Dir.php +++ b/lib/internal/Magento/Framework/Module/Dir.php @@ -45,8 +45,9 @@ public function getDir($moduleName, $type = '') { $path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName); - if (!isset($path)) { - // (Do not throw \LogicException, as it would break backwards-compatibility.) + // An empty $type means it's gettind the directory of the module itself. + if (empty($type) && !isset($path)) { + // Note: do not throw \LogicException, as it would break backwards-compatibility. throw new \InvalidArgumentException("Component '$moduleName' of type '$type' is not correctly registered."); } From 57a6e17413d6626122e225d8ee4441ca45c7e94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Elmeris?= Date: Fri, 22 Dec 2017 23:21:34 +0200 Subject: [PATCH 4/6] Fix misspelling. --- lib/internal/Magento/Framework/Module/Dir.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Module/Dir.php b/lib/internal/Magento/Framework/Module/Dir.php index 309fa33778de4..8ce818961cdf8 100644 --- a/lib/internal/Magento/Framework/Module/Dir.php +++ b/lib/internal/Magento/Framework/Module/Dir.php @@ -45,7 +45,7 @@ public function getDir($moduleName, $type = '') { $path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName); - // An empty $type means it's gettind the directory of the module itself. + // An empty $type means it's getting the directory of the module itself. if (empty($type) && !isset($path)) { // Note: do not throw \LogicException, as it would break backwards-compatibility. throw new \InvalidArgumentException("Component '$moduleName' of type '$type' is not correctly registered."); From 70b2722cbbe33d35ac4c90cfa13d7adca2747454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Elmeris?= Date: Fri, 22 Dec 2017 23:37:43 +0200 Subject: [PATCH 5/6] Simpler message, as this appears only for the modules themselves. --- lib/internal/Magento/Framework/Module/Dir.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Module/Dir.php b/lib/internal/Magento/Framework/Module/Dir.php index 8ce818961cdf8..688c7c43ac0e4 100644 --- a/lib/internal/Magento/Framework/Module/Dir.php +++ b/lib/internal/Magento/Framework/Module/Dir.php @@ -48,7 +48,7 @@ public function getDir($moduleName, $type = '') // An empty $type means it's getting the directory of the module itself. if (empty($type) && !isset($path)) { // Note: do not throw \LogicException, as it would break backwards-compatibility. - throw new \InvalidArgumentException("Component '$moduleName' of type '$type' is not correctly registered."); + throw new \InvalidArgumentException("Module '$moduleName' is not correctly registered."); } if ($type) { From d77d9a0c1a1324d968f0c38001bbc40a7d8a13d3 Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Mon, 19 Feb 2018 16:22:12 +0200 Subject: [PATCH 6/6] [Forwardport] Display a more meaningful error message in case of misspelled module name. Cover new code with tests. --- .../Magento/Framework/Module/Test/Unit/DirTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/DirTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/DirTest.php index 335228888cc4b..055e4be71baf1 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/DirTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/DirTest.php @@ -59,4 +59,17 @@ public function testGetDirModuleSubDirUnknown() $this->_model->getDir('Test_Module', 'unknown'); } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Module 'Test Module' is not correctly registered. + */ + public function testGetDirModuleIncorrectlyRegistered() + { + $this->moduleRegistryMock->expects($this->once()) + ->method('getPath') + ->with($this->identicalTo(ComponentRegistrar::MODULE), $this->identicalTo('Test Module')) + ->willReturn(null); + $this->_model->getDir('Test Module'); + } }