[icinga-checkins] icinga.org: icingaweb2/feature/add-to-dashboard-4537: Show the user a senseful error message in case enabledModules is missing

git at icinga.org git at icinga.org
Tue Nov 18 17:03:11 CET 2014


Module: icingaweb2
Branch: feature/add-to-dashboard-4537
Commit: f00766323598c9ce5ccad2f70f464a7758ac942d
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=f00766323598c9ce5ccad2f70f464a7758ac942d

Author: Johannes Meyer <johannes.meyer at netways.de>
Date:   Tue Nov 18 16:22:33 2014 +0100

Show the user a senseful error message in case enabledModules is missing

fixes #7205

---

 library/Icinga/Application/Modules/Manager.php |    8 ++++++--
 library/Icinga/Exception/NotFoundError.php     |    9 +++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/library/Icinga/Application/Modules/Manager.php b/library/Icinga/Application/Modules/Manager.php
index 8857bf2..78e505d 100644
--- a/library/Icinga/Application/Modules/Manager.php
+++ b/library/Icinga/Application/Modules/Manager.php
@@ -13,6 +13,7 @@ use Icinga\Exception\ConfigurationError;
 use Icinga\Exception\SystemPermissionException;
 use Icinga\Exception\ProgrammingError;
 use Icinga\Exception\NotReadableError;
+use Icinga\Exception\NotFoundError;
 
 /**
  * Module manager that handles detecting, enabling and disabling of modules
@@ -228,6 +229,7 @@ class Manager
      *
      * @return  self
      * @throws  ConfigurationError          When trying to enable a module that is not installed
+     * @throws  NotFoundError               In case the "enabledModules" directory does not exist
      * @throws  SystemPermissionException   When insufficient permissions for the application exist
      */
     public function enableModule($name)
@@ -245,9 +247,11 @@ class Manager
         $target = $this->installedBaseDirs[$name];
         $link = $this->enableDir . '/' . $name;
 
-        if (!is_writable($this->enableDir)) {
+        if (! is_dir($this->enableDir)) {
+            throw new NotFoundError('Cannot enable module "%s". Path "%s" not found.', $name, $this->enableDir);
+        } elseif (!is_writable($this->enableDir)) {
             throw new SystemPermissionException(
-                'Can not enable module "%s". Insufficient system permissions for enabling modules.',
+                'Cannot enable module "%s". Insufficient system permissions for enabling modules.',
                 $name
             );
         }
diff --git a/library/Icinga/Exception/NotFoundError.php b/library/Icinga/Exception/NotFoundError.php
new file mode 100644
index 0000000..c90b032
--- /dev/null
+++ b/library/Icinga/Exception/NotFoundError.php
@@ -0,0 +1,9 @@
+<?php
+// {{{ICINGA_LICENSE_HEADER}}}
+// {{{ICINGA_LICENSE_HEADER}}}
+
+namespace Icinga\Exception;
+
+class NotFoundError extends IcingaException
+{
+}



More information about the icinga-checkins mailing list