From 9c5878cbbe2516b8b17b470136cb2652f4700560 Mon Sep 17 00:00:00 2001 From: Alexander Klimov Date: Fri, 22 Aug 2014 11:46:11 +0200 Subject: [PATCH] ConfigurationError: extend IcingaException refs #6931 --- .../Icinga/Application/Modules/Manager.php | 16 ++++++----- library/Icinga/Authentication/AuthChain.php | 4 ++- library/Icinga/Authentication/UserBackend.php | 28 +++++++++++-------- library/Icinga/Data/Db/DbConnection.php | 5 +++- library/Icinga/Data/ResourceFactory.php | 8 ++++-- .../Icinga/Exception/ConfigurationError.php | 2 +- library/Icinga/Logger/Logger.php | 5 +++- library/Icinga/Logger/Writer/FileWriter.php | 11 ++++++-- library/Icinga/Logger/Writer/SyslogWriter.php | 3 +- .../Commandpipe/Transport/LocalPipe.php | 8 ++---- library/Icinga/Protocol/Statusdat/Reader.php | 6 ++-- .../User/Preferences/PreferencesStore.php | 3 +- library/Icinga/Web/Widget/Dashboard/Pane.php | 2 +- .../controllers/CommandController.php | 2 +- .../monitoring/library/Monitoring/Backend.php | 5 ++-- 15 files changed, 68 insertions(+), 40 deletions(-) diff --git a/library/Icinga/Application/Modules/Manager.php b/library/Icinga/Application/Modules/Manager.php index 28241adc3..366f77c30 100644 --- a/library/Icinga/Application/Modules/Manager.php +++ b/library/Icinga/Application/Modules/Manager.php @@ -206,10 +206,8 @@ class Manager { if (!$this->hasInstalled($name)) { throw new ConfigurationError( - sprintf( - 'Cannot enable module "%s". Module is not installed.', - $name - ) + 'Cannot enable module "%s". Module is not installed.', + $name ); } @@ -268,14 +266,18 @@ class Manager } $link = $this->enableDir . '/' . $name; if (!file_exists($link)) { - throw new ConfigurationError('Could not disable module. The module ' . $name . ' was not found.'); + throw new ConfigurationError( + 'Could not disable module. The module %s was not found.', + $name + ); } if (!is_link($link)) { throw new ConfigurationError( - 'Could not disable module. The module "' . $name . '" is not a symlink. ' + 'Could not disable module. The module "%s" is not a symlink. ' . 'It looks like you have installed this module manually and moved it to your module folder. ' . 'In order to dynamically enable and disable modules, you have to create a symlink to ' - . 'the enabled_modules folder.' + . 'the enabled_modules folder.', + $name ); } diff --git a/library/Icinga/Authentication/AuthChain.php b/library/Icinga/Authentication/AuthChain.php index 216344735..4ab87f7ae 100644 --- a/library/Icinga/Authentication/AuthChain.php +++ b/library/Icinga/Authentication/AuthChain.php @@ -97,7 +97,9 @@ class AuthChain implements Iterator } catch (ConfigurationError $e) { Logger::error( new ConfigurationError( - 'Cannot create authentication backend "' . $name . '". An exception was thrown:', 0, $e + 'Cannot create authentication backend "%s". An exception was thrown:', + $name, + $e ) ); $this->next(); diff --git a/library/Icinga/Authentication/UserBackend.php b/library/Icinga/Authentication/UserBackend.php index f90eef1c7..9e7abd62a 100644 --- a/library/Icinga/Authentication/UserBackend.php +++ b/library/Icinga/Authentication/UserBackend.php @@ -54,16 +54,18 @@ abstract class UserBackend implements Countable // Use a custom backend class, this is only useful for testing if (!class_exists($backendConfig->class)) { throw new ConfigurationError( - 'Authentication configuration for backend "' . $name . '" defines an invalid backend' - . ' class. Backend class "' . $backendConfig->class. '" not found' + 'Authentication configuration for backend "%s" defines an invalid backend class.' + . ' Backend class "%s" not found', + $name, + $backendConfig->class ); } return new $backendConfig->class($backendConfig); } if (($backendType = $backendConfig->backend) === null) { throw new ConfigurationError( - 'Authentication configuration for backend "' . $name - . '" is missing the backend directive' + 'Authentication configuration for backend "%s" is missing the backend directive', + $name ); } $backendType = strtolower($backendType); @@ -74,8 +76,8 @@ abstract class UserBackend implements Countable } if ($backendConfig->resource === null) { throw new ConfigurationError( - 'Authentication configuration for backend "' . $name - . '" is missing the resource directive' + 'Authentication configuration for backend "%s" is missing the resource directive', + $name ); } try { @@ -100,22 +102,24 @@ abstract class UserBackend implements Countable case 'ldap': if (($userClass = $backendConfig->user_class) === null) { throw new ConfigurationError( - 'Authentication configuration for backend "' . $name - . '" is missing the user_class directive' + 'Authentication configuration for backend "%s" is missing the user_class directive', + $name ); } if (($userNameAttribute = $backendConfig->user_name_attribute) === null) { throw new ConfigurationError( - 'Authentication configuration for backend "' . $name - . '" is missing the user_name_attribute directive' + 'Authentication configuration for backend "%s" is missing the user_name_attribute directive', + $name ); } $backend = new LdapUserBackend($resource, $userClass, $userNameAttribute); break; default: throw new ConfigurationError( - 'Authentication configuration for backend "' . $name. '" defines an invalid backend' - . ' type. Backend type "' . $backendType . '" is not supported' + 'Authentication configuration for backend "%s" defines an invalid backend type.' + . ' Backend type "%s" is not supported', + $name, + $backendType ); } $backend->setName($name); diff --git a/library/Icinga/Data/Db/DbConnection.php b/library/Icinga/Data/Db/DbConnection.php index af9cce05c..da05a429f 100644 --- a/library/Icinga/Data/Db/DbConnection.php +++ b/library/Icinga/Data/Db/DbConnection.php @@ -142,7 +142,10 @@ class DbConnection implements Selectable } break;*/ default: - throw new ConfigurationError(sprintf('Backend "%s" is not supported', $this->dbType)); + throw new ConfigurationError( + 'Backend "%s" is not supported', + $this->dbType + ); } $this->dbAdapter = Zend_Db::factory($adapter, $adapterParamaters); $this->dbAdapter->setFetchMode(Zend_Db::FETCH_OBJ); diff --git a/library/Icinga/Data/ResourceFactory.php b/library/Icinga/Data/ResourceFactory.php index 1db623e17..b7156bb50 100644 --- a/library/Icinga/Data/ResourceFactory.php +++ b/library/Icinga/Data/ResourceFactory.php @@ -39,7 +39,8 @@ class ResourceFactory implements ConfigAwareFactory self::assertResourcesExist(); if (($resourceConfig = self::$resources->get($resourceName)) === null) { throw new ConfigurationError( - 'Cannot load resource config "' . $resourceName . '". Resource does not exist' + 'Cannot load resource config "%s". Resource does not exist', + $resourceName ); } return $resourceConfig; @@ -113,7 +114,10 @@ class ResourceFactory implements ConfigAwareFactory $resource = new FileReader($config); break; default: - throw new ConfigurationError('Unsupported resource type "' . $config->type . '"'); + throw new ConfigurationError( + 'Unsupported resource type "%s"', + $config->type + ); } return $resource; } diff --git a/library/Icinga/Exception/ConfigurationError.php b/library/Icinga/Exception/ConfigurationError.php index 988246f5f..aee601a62 100644 --- a/library/Icinga/Exception/ConfigurationError.php +++ b/library/Icinga/Exception/ConfigurationError.php @@ -8,6 +8,6 @@ namespace Icinga\Exception; * Class ConfigurationError * @package Icinga\Exception */ -class ConfigurationError extends \RuntimeException +class ConfigurationError extends IcingaException { } diff --git a/library/Icinga/Logger/Logger.php b/library/Icinga/Logger/Logger.php index 31b0452d2..87811ae69 100644 --- a/library/Icinga/Logger/Logger.php +++ b/library/Icinga/Logger/Logger.php @@ -79,7 +79,10 @@ class Logger { $class = 'Icinga\\Logger\\Writer\\' . ucfirst(strtolower($config->type)) . 'Writer'; if (!class_exists($class)) { - throw new ConfigurationError('Cannot find log writer of type "' . $config->type . '"'); + throw new ConfigurationError( + 'Cannot find log writer of type "%s"', + $config->type + ); } return new $class($config); diff --git a/library/Icinga/Logger/Writer/FileWriter.php b/library/Icinga/Logger/Writer/FileWriter.php index fef2e8bc7..2795b3541 100644 --- a/library/Icinga/Logger/Writer/FileWriter.php +++ b/library/Icinga/Logger/Writer/FileWriter.php @@ -33,13 +33,20 @@ class FileWriter extends LogWriter $this->path = $config->target; if (substr($this->path, 0, 6) !== 'php://' && false === file_exists(dirname($this->path))) { - throw new ConfigurationError('Log path "' . dirname($this->path) . '" does not exist'); + throw new ConfigurationError( + 'Log path "%s" does not exist', + dirname($this->path) + ); } try { $this->write(''); // Avoid to handle such errors on every write access } catch (Exception $e) { - throw new ConfigurationError('Cannot write to log file "' . $this->path . '" (' . $e->getMessage() . ')'); + throw new ConfigurationError( + 'Cannot write to log file "%s" (%s)', + $this->path, + $e->getMessage() + ); } } diff --git a/library/Icinga/Logger/Writer/SyslogWriter.php b/library/Icinga/Logger/Writer/SyslogWriter.php index fea20b592..8f7711a8a 100644 --- a/library/Icinga/Logger/Writer/SyslogWriter.php +++ b/library/Icinga/Logger/Writer/SyslogWriter.php @@ -45,7 +45,8 @@ class SyslogWriter extends LogWriter { if (!array_key_exists($config->facility, $this->facilities)) { throw new ConfigurationError( - 'Cannot create syslog writer with unknown facility "' . $config->facility . '"' + 'Cannot create syslog writer with unknown facility "%s"', + $config->facility ); } diff --git a/library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php b/library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php index ecf1a981c..32f745565 100644 --- a/library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php +++ b/library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php @@ -49,11 +49,9 @@ class LocalPipe implements Transport $file->fflush(); } catch (Exception $e) { throw new ConfigurationError( - sprintf( - 'Could not open icinga command pipe at "%s" (%s)', - $this->path, - $e->getMessage() - ) + 'Could not open icinga command pipe at "%s" (%s)', + $this->path, + $e->getMessage() ); } diff --git a/library/Icinga/Protocol/Statusdat/Reader.php b/library/Icinga/Protocol/Statusdat/Reader.php index e9b767127..6891e7ba8 100644 --- a/library/Icinga/Protocol/Statusdat/Reader.php +++ b/library/Icinga/Protocol/Statusdat/Reader.php @@ -246,7 +246,8 @@ class Reader implements IReader, Selectable { if (!is_readable($this->config->object_file)) { throw new ConfigurationError( - 'Can\'t read object-file "' . $this->config->object_file . '", check your configuration' + 'Can\'t read object-file "%s", check your configuration', + $this->config->object_file ); } if (!$this->parser) { @@ -265,7 +266,8 @@ class Reader implements IReader, Selectable { if (!is_readable($this->config->status_file)) { throw new ConfigurationError( - "Can't read status-file {$this->config->status_file}, check your configuration" + 'Can\'t read status-file %s, check your configuration', + $this->config->status_file ); } if (!$this->parser) { diff --git a/library/Icinga/User/Preferences/PreferencesStore.php b/library/Icinga/User/Preferences/PreferencesStore.php index 81d47b394..749d054dc 100644 --- a/library/Icinga/User/Preferences/PreferencesStore.php +++ b/library/Icinga/User/Preferences/PreferencesStore.php @@ -127,7 +127,8 @@ abstract class PreferencesStore $storeClass = 'Icinga\\User\\Preferences\\Store\\' . $type . 'Store'; if (!class_exists($storeClass)) { throw new ConfigurationError( - 'Preferences configuration defines an invalid storage type. Storage type ' . $type . ' not found' + 'Preferences configuration defines an invalid storage type. Storage type %s not found', + $type ); } diff --git a/library/Icinga/Web/Widget/Dashboard/Pane.php b/library/Icinga/Web/Widget/Dashboard/Pane.php index 5e3e8ffea..05d121385 100644 --- a/library/Icinga/Web/Widget/Dashboard/Pane.php +++ b/library/Icinga/Web/Widget/Dashboard/Pane.php @@ -157,7 +157,7 @@ class Pane extends AbstractWidget } elseif (is_string($component) && $url !== null) { $this->components[$component] = new Component($component, $url, $this); } else { - throw new ConfigurationError('Invalid component added: ' . $component); + throw new ConfigurationError('Invalid component added: %s', $component); } return $this; } diff --git a/modules/monitoring/application/controllers/CommandController.php b/modules/monitoring/application/controllers/CommandController.php index bb1abcc74..f3055371a 100644 --- a/modules/monitoring/application/controllers/CommandController.php +++ b/modules/monitoring/application/controllers/CommandController.php @@ -114,7 +114,7 @@ class Monitoring_CommandController extends Controller if ($targetConfig->get($instance)) { $this->target = new CommandPipe($targetConfig->get($instance)); } else { - throw new ConfigurationError('Instance is not configured: '. $instance); + throw new ConfigurationError('Instance is not configured: %s', $instance); } } else { if ($targetConfig && $targetInfo = $targetConfig->current()) { diff --git a/modules/monitoring/library/Monitoring/Backend.php b/modules/monitoring/library/Monitoring/Backend.php index 21f2b91db..8131e7c1c 100644 --- a/modules/monitoring/library/Monitoring/Backend.php +++ b/modules/monitoring/library/Monitoring/Backend.php @@ -87,12 +87,13 @@ class Backend implements Selectable, Queryable, ConnectionInterface $backendConfig = $defaultBackend; } else { if (!array_key_exists($backendName, $allBackends)) { - throw new ConfigurationError('No configuration for backend ' . $backendName); + throw new ConfigurationError('No configuration for backend %s', $backendName); } $backendConfig = $allBackends[$backendName]; if ((bool) $backendConfig->get('disabled', false)) { throw new ConfigurationError( - 'Configuration for backend ' . $backendName . ' available but backend is disabled' + 'Configuration for backend %s available but backend is disabled', + $backendName ); } }