Merge branch 'bugfix/exceptions-with-printf-params-6931'

fixes #6931
This commit is contained in:
Alexander Klimov 2014-08-26 11:25:51 +02:00
commit aec66570d6
46 changed files with 263 additions and 185 deletions

View File

@ -61,7 +61,10 @@ class Config extends Zend_Config
$this->configFile = $filepath; $this->configFile = $filepath;
$this->merge(new Zend_Config_Ini($filepath)); $this->merge(new Zend_Config_Ini($filepath));
} else { } else {
throw new NotReadableError('Cannot read config file "' . $filename . '". Permission denied'); throw new NotReadableError(
'Cannot read config file "%s". Permission denied',
$filename
);
} }
} }

View File

@ -39,11 +39,11 @@ class Loader
public function registerNamespace($namespace, $directory) public function registerNamespace($namespace, $directory)
{ {
if (!is_dir($directory)) { if (!is_dir($directory)) {
throw new ProgrammingError(sprintf( throw new ProgrammingError(
'Directory "%s" for namespace "%s" does not exist', 'Directory "%s" for namespace "%s" does not exist',
$directory, $directory,
$namespace $namespace
)); );
} }
$this->namespaces[$namespace] = $directory; $this->namespaces[$namespace] = $directory;

View File

@ -110,12 +110,14 @@ class Manager
} }
if (!is_dir($this->enableDir)) { if (!is_dir($this->enableDir)) {
throw new NotReadableError( throw new NotReadableError(
'Cannot read enabled modules. Module directory "' . $this->enableDir . '" is not a directory' 'Cannot read enabled modules. Module directory "%s" is not a directory',
$this->enableDir
); );
} }
if (!is_readable($this->enableDir)) { if (!is_readable($this->enableDir)) {
throw new NotReadableError( throw new NotReadableError(
'Cannot read enabled modules. Module directory "' . $this->enableDir . '" is not readable' 'Cannot read enabled modules. Module directory "%s" is not readable',
$this->enableDir
); );
} }
if (($dh = opendir($canonical)) !== false) { if (($dh = opendir($canonical)) !== false) {
@ -206,10 +208,8 @@ class Manager
{ {
if (!$this->hasInstalled($name)) { if (!$this->hasInstalled($name)) {
throw new ConfigurationError( throw new ConfigurationError(
sprintf(
'Cannot enable module "%s". Module is not installed.', 'Cannot enable module "%s". Module is not installed.',
$name $name
)
); );
} }
@ -219,8 +219,8 @@ class Manager
if (!is_writable($this->enableDir)) { if (!is_writable($this->enableDir)) {
throw new SystemPermissionException( throw new SystemPermissionException(
'Can not enable module "' . $name . '". ' 'Can not enable module "%s". Insufficient system permissions for enabling modules.',
. 'Insufficient system permissions for enabling modules.' $name
); );
} }
@ -232,9 +232,11 @@ class Manager
$error = error_get_last(); $error = error_get_last();
if (strstr($error["message"], "File exists") === false) { if (strstr($error["message"], "File exists") === false) {
throw new SystemPermissionException( throw new SystemPermissionException(
'Could not enable module "' . $name . '" due to file system errors. ' 'Could not enable module "%s" due to file system errors. '
. 'Please check path and mounting points because this is not a permission error. ' . 'Please check path and mounting points because this is not a permission error. '
. 'Primary error was: ' . $error['message'] . 'Primary error was: %s',
$name,
$error['message']
); );
} }
} }
@ -268,14 +270,18 @@ class Manager
} }
$link = $this->enableDir . '/' . $name; $link = $this->enableDir . '/' . $name;
if (!file_exists($link)) { 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)) { if (!is_link($link)) {
throw new ConfigurationError( 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. ' . '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 ' . 'In order to dynamically enable and disable modules, you have to create a symlink to '
. 'the enabled_modules folder.' . 'the enabled_modules folder.',
$name
); );
} }
@ -283,9 +289,11 @@ class Manager
if (!@unlink($link)) { if (!@unlink($link)) {
$error = error_get_last(); $error = error_get_last();
throw new SystemPermissionException( throw new SystemPermissionException(
'Could not disable module "' . $name . '" due to file system errors. ' 'Could not disable module "%s" due to file system errors. '
. 'Please check path and mounting points because this is not a permission error. ' . 'Please check path and mounting points because this is not a permission error. '
. 'Primary error was: ' . $error['message'] . 'Primary error was: %s',
$name,
$error['message']
); );
} }
} }
@ -319,10 +327,8 @@ class Manager
} }
throw new ProgrammingError( throw new ProgrammingError(
sprintf(
'Trying to access uninstalled module dir: %s', 'Trying to access uninstalled module dir: %s',
$name $name
)
); );
} }
@ -388,10 +394,8 @@ class Manager
{ {
if (!$this->hasLoaded($name)) { if (!$this->hasLoaded($name)) {
throw new ProgrammingError( throw new ProgrammingError(
sprintf(
'Cannot access module %s as it hasn\'t been loaded', 'Cannot access module %s as it hasn\'t been loaded',
$name $name
)
); );
} }
return $this->loadedModules[$name]; return $this->loadedModules[$name];

View File

@ -97,7 +97,9 @@ class AuthChain implements Iterator
} catch (ConfigurationError $e) { } catch (ConfigurationError $e) {
Logger::error( Logger::error(
new ConfigurationError( 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(); $this->next();

View File

@ -73,12 +73,9 @@ class DbUserBackend extends UserBackend
return ($row !== false) ? true : false; return ($row !== false) ? true : false;
} catch (Exception $e) { } catch (Exception $e) {
throw new AuthenticationException( throw new AuthenticationException(
sprintf(
'Failed to authenticate user "%s" against backend "%s". An exception was thrown:', 'Failed to authenticate user "%s" against backend "%s". An exception was thrown:',
$user->getUsername(), $user->getUsername(),
$this->getName() $this->getName(),
),
0,
$e $e
); );
} }

View File

@ -68,21 +68,17 @@ class LdapUserBackend extends UserBackend
$result = $q->fetchRow(); $result = $q->fetchRow();
if (! isset($result)) { if (! isset($result)) {
throw new AuthenticationException( throw new AuthenticationException(
sprintf(
'No objects with objectClass="%s" in DN="%s" found.', 'No objects with objectClass="%s" in DN="%s" found.',
$this->userClass, $this->userClass,
$this->conn->getDN() $this->conn->getDN()
)
); );
} }
if (! isset($result->{$this->userNameAttribute})) { if (! isset($result->{$this->userNameAttribute})) {
throw new AuthenticationException( throw new AuthenticationException(
sprintf(
'UserNameAttribute "%s" not existing in objectClass="%s"', 'UserNameAttribute "%s" not existing in objectClass="%s"',
$this->userNameAttribute, $this->userNameAttribute,
$this->userClass $this->userClass
)
); );
} }
} }
@ -121,11 +117,8 @@ class LdapUserBackend extends UserBackend
} catch (AuthenticationException $e) { } catch (AuthenticationException $e) {
// Authentication not possible // Authentication not possible
throw new AuthenticationException( throw new AuthenticationException(
sprintf(
'Authentication against backend "%s" not possible: ', 'Authentication against backend "%s" not possible: ',
$this->getName() $this->getName(),
),
0,
$e $e
); );
} }
@ -141,12 +134,9 @@ class LdapUserBackend extends UserBackend
} catch (LdapException $e) { } catch (LdapException $e) {
// Error during authentication of this specific user // Error during authentication of this specific user
throw new AuthenticationException( throw new AuthenticationException(
sprintf(
'Failed to authenticate user "%s" against backend "%s". An exception was thrown:', 'Failed to authenticate user "%s" against backend "%s". An exception was thrown:',
$user->getUsername(), $user->getUsername(),
$this->getName() $this->getName(),
),
0,
$e $e
); );
} }

View File

@ -54,16 +54,18 @@ abstract class UserBackend implements Countable
// Use a custom backend class, this is only useful for testing // Use a custom backend class, this is only useful for testing
if (!class_exists($backendConfig->class)) { if (!class_exists($backendConfig->class)) {
throw new ConfigurationError( throw new ConfigurationError(
'Authentication configuration for backend "' . $name . '" defines an invalid backend' 'Authentication configuration for backend "%s" defines an invalid backend class.'
. ' class. Backend class "' . $backendConfig->class. '" not found' . ' Backend class "%s" not found',
$name,
$backendConfig->class
); );
} }
return new $backendConfig->class($backendConfig); return new $backendConfig->class($backendConfig);
} }
if (($backendType = $backendConfig->backend) === null) { if (($backendType = $backendConfig->backend) === null) {
throw new ConfigurationError( throw new ConfigurationError(
'Authentication configuration for backend "' . $name 'Authentication configuration for backend "%s" is missing the backend directive',
. '" is missing the backend directive' $name
); );
} }
$backendType = strtolower($backendType); $backendType = strtolower($backendType);
@ -74,8 +76,8 @@ abstract class UserBackend implements Countable
} }
if ($backendConfig->resource === null) { if ($backendConfig->resource === null) {
throw new ConfigurationError( throw new ConfigurationError(
'Authentication configuration for backend "' . $name 'Authentication configuration for backend "%s" is missing the resource directive',
. '" is missing the resource directive' $name
); );
} }
try { try {
@ -100,22 +102,24 @@ abstract class UserBackend implements Countable
case 'ldap': case 'ldap':
if (($userClass = $backendConfig->user_class) === null) { if (($userClass = $backendConfig->user_class) === null) {
throw new ConfigurationError( throw new ConfigurationError(
'Authentication configuration for backend "' . $name 'Authentication configuration for backend "%s" is missing the user_class directive',
. '" is missing the user_class directive' $name
); );
} }
if (($userNameAttribute = $backendConfig->user_name_attribute) === null) { if (($userNameAttribute = $backendConfig->user_name_attribute) === null) {
throw new ConfigurationError( throw new ConfigurationError(
'Authentication configuration for backend "' . $name 'Authentication configuration for backend "%s" is missing the user_name_attribute directive',
. '" is missing the user_name_attribute directive' $name
); );
} }
$backend = new LdapUserBackend($resource, $userClass, $userNameAttribute); $backend = new LdapUserBackend($resource, $userClass, $userNameAttribute);
break; break;
default: default:
throw new ConfigurationError( throw new ConfigurationError(
'Authentication configuration for backend "' . $name. '" defines an invalid backend' 'Authentication configuration for backend "%s" defines an invalid backend type.'
. ' type. Backend type "' . $backendType . '" is not supported' . ' Backend type "%s" is not supported',
$name,
$backendType
); );
} }
$backend->setName($name); $backend->setName($name);

View File

@ -332,7 +332,8 @@ class Loader
{ {
if (! $this->hasModule($module)) { if (! $this->hasModule($module)) {
throw new ProgrammingError( throw new ProgrammingError(
sprintf('There is no such module: %s', $module) 'There is no such module: %s',
$module
); );
} }
} }
@ -341,7 +342,8 @@ class Loader
{ {
if (! $this->hasCommand($command)) { if (! $this->hasCommand($command)) {
throw new ProgrammingError( throw new ProgrammingError(
sprintf('There is no such command: %s', $command) 'There is no such command: %s',
$command
); );
} }
} }
@ -351,7 +353,9 @@ class Loader
$this->assertModuleExists($module); $this->assertModuleExists($module);
if (! $this->hasModuleCommand($module, $command)) { if (! $this->hasModuleCommand($module, $command)) {
throw new ProgrammingError( throw new ProgrammingError(
sprintf("The module '%s' has no such command: %s", $module, $command) 'The module \'%s\' has no such command: %s',
$module,
$command
); );
} }
} }

View File

@ -142,7 +142,10 @@ class DbConnection implements Selectable
} }
break;*/ break;*/
default: 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 = Zend_Db::factory($adapter, $adapterParamaters);
$this->dbAdapter->setFetchMode(Zend_Db::FETCH_OBJ); $this->dbAdapter->setFetchMode(Zend_Db::FETCH_OBJ);

View File

@ -34,9 +34,12 @@ abstract class Filter
if ((string) $id === $this->getId()) { if ((string) $id === $this->getId()) {
return $this; return $this;
} }
throw new ProgrammingError(sprintf( throw new ProgrammingError(
'Trying to get invalid filter index "%s" from "%s" ("%s")', $id, $this, $this->id 'Trying to get invalid filter index "%s" from "%s" ("%s")',
)); $id,
$this,
$this->id
);
} }
public function getId() public function getId()
@ -136,7 +139,8 @@ abstract class Filter
case '<=': return new FilterEqualOrLessThan($col, $op, $expression); case '<=': return new FilterEqualOrLessThan($col, $op, $expression);
case '!=': return new FilterNotEqual($col, $op, $expression); case '!=': return new FilterNotEqual($col, $op, $expression);
default: throw new ProgrammingError( default: throw new ProgrammingError(
sprintf('There is no such filter sign: %s', $op) 'There is no such filter sign: %s',
$op
); );
} }
} }
@ -203,7 +207,8 @@ abstract class Filter
case 'NOT': return self::not($filters); case 'NOT': return self::not($filters);
} }
throw new ProgrammingError( throw new ProgrammingError(
sprintf('"%s" is not a valid filter chain operator', $operator) '"%s" is not a valid filter chain operator',
$operator
); );
} }

View File

@ -39,7 +39,8 @@ class ResourceFactory implements ConfigAwareFactory
self::assertResourcesExist(); self::assertResourcesExist();
if (($resourceConfig = self::$resources->get($resourceName)) === null) { if (($resourceConfig = self::$resources->get($resourceName)) === null) {
throw new ConfigurationError( throw new ConfigurationError(
'Cannot load resource config "' . $resourceName . '". Resource does not exist' 'Cannot load resource config "%s". Resource does not exist',
$resourceName
); );
} }
return $resourceConfig; return $resourceConfig;
@ -77,7 +78,7 @@ class ResourceFactory implements ConfigAwareFactory
{ {
if (!isset(self::$resources)) { if (!isset(self::$resources)) {
throw new ProgrammingError( throw new ProgrammingError(
"The ResourceFactory must be initialised by setting a config, before it can be used" 'The ResourceFactory must be initialised by setting a config, before it can be used'
); );
} }
} }
@ -113,7 +114,10 @@ class ResourceFactory implements ConfigAwareFactory
$resource = new FileReader($config); $resource = new FileReader($config);
break; break;
default: default:
throw new ConfigurationError('Unsupported resource type "' . $config->type . '"'); throw new ConfigurationError(
'Unsupported resource type "%s"',
$config->type
);
} }
return $resource; return $resource;
} }

View File

@ -4,11 +4,9 @@
namespace Icinga\Exception; namespace Icinga\Exception;
use RuntimeException;
/** /**
* Exception thrown if an error occurs during authentication * Exception thrown if an error occurs during authentication
*/ */
class AuthenticationException extends RuntimeException class AuthenticationException extends IcingaException
{ {
} }

View File

@ -8,6 +8,6 @@ namespace Icinga\Exception;
* Class ConfigurationError * Class ConfigurationError
* @package Icinga\Exception * @package Icinga\Exception
*/ */
class ConfigurationError extends \RuntimeException class ConfigurationError extends IcingaException
{ {
} }

View File

@ -0,0 +1,29 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Exception;
use Exception;
class IcingaException extends Exception
{
/**
* @param string $message format string for vsprintf()
* Any futher args: args for vsprintf()
* @see vsprintf
*
* If there is at least one exception, the last one will be also used for the exception chaining.
*/
public function __construct($message = '')
{
$args = array_slice(func_get_args(), 1);
$exc = null;
foreach ($args as &$arg) {
if ($arg instanceof Exception) {
$exc = $arg;
}
}
parent::__construct(vsprintf($message, $args), 0, $exc);
}
}

View File

@ -4,12 +4,10 @@
namespace Icinga\Exception; namespace Icinga\Exception;
use RuntimeException;
/** /**
* Class MissingParameterException * Class MissingParameterException
* @package Icinga\Exception * @package Icinga\Exception
*/ */
class MissingParameterException extends RuntimeException class MissingParameterException extends IcingaException
{ {
} }

View File

@ -8,6 +8,6 @@ namespace Icinga\Exception;
* Class NotImplementedError * Class NotImplementedError
* @package Icinga\Exception * @package Icinga\Exception
*/ */
class NotImplementedError extends \Exception class NotImplementedError extends IcingaException
{ {
} }

View File

@ -4,8 +4,6 @@
namespace Icinga\Exception; namespace Icinga\Exception;
use RuntimeException; class NotReadableError extends IcingaException
class NotReadableError extends RuntimeException
{ {
} }

View File

@ -4,8 +4,6 @@
namespace Icinga\Exception; namespace Icinga\Exception;
use RuntimeException; class NotWritableError extends IcingaException
class NotWritableError extends RuntimeException
{ {
} }

View File

@ -8,6 +8,6 @@ namespace Icinga\Exception;
* Class ProgrammingError * Class ProgrammingError
* @package Icinga\Exception * @package Icinga\Exception
*/ */
class ProgrammingError extends \Exception class ProgrammingError extends IcingaException
{ {
} }

View File

@ -4,11 +4,9 @@
namespace Icinga\Exception; namespace Icinga\Exception;
use \Exception;
/** /**
* Handle problems according to file system permissions * Handle problems according to file system permissions
*/ */
class SystemPermissionException extends Exception class SystemPermissionException extends IcingaException
{ {
} }

View File

@ -79,7 +79,10 @@ class Logger
{ {
$class = 'Icinga\\Logger\\Writer\\' . ucfirst(strtolower($config->type)) . 'Writer'; $class = 'Icinga\\Logger\\Writer\\' . ucfirst(strtolower($config->type)) . 'Writer';
if (!class_exists($class)) { 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); return new $class($config);

View File

@ -33,13 +33,20 @@ class FileWriter extends LogWriter
$this->path = $config->target; $this->path = $config->target;
if (substr($this->path, 0, 6) !== 'php://' && false === file_exists(dirname($this->path))) { 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 { try {
$this->write(''); // Avoid to handle such errors on every write access $this->write(''); // Avoid to handle such errors on every write access
} catch (Exception $e) { } 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()
);
} }
} }

View File

@ -45,7 +45,8 @@ class SyslogWriter extends LogWriter
{ {
if (!array_key_exists($config->facility, $this->facilities)) { if (!array_key_exists($config->facility, $this->facilities)) {
throw new ConfigurationError( throw new ConfigurationError(
'Cannot create syslog writer with unknown facility "' . $config->facility . '"' 'Cannot create syslog writer with unknown facility "%s"',
$config->facility
); );
} }

View File

@ -138,7 +138,10 @@ abstract class Command
*/ */
public function getHostgroupCommand($hostgroup) public function getHostgroupCommand($hostgroup)
{ {
throw new ProgrammingError(get_class($this) . ' does not provide a hostgroup command'); throw new ProgrammingError(
'%s does not provide a hostgroup command',
get_class($this)
);
} }
/** /**
@ -150,7 +153,10 @@ abstract class Command
*/ */
public function getServicegroupCommand($servicegroup) public function getServicegroupCommand($servicegroup)
{ {
throw new ProgrammingError(get_class($this) . ' does not provide a servicegroup command'); throw new ProgrammingError(
'%s does not provide a servicegroup command',
get_class($this)
);
} }
/** /**
@ -163,6 +169,9 @@ abstract class Command
*/ */
public function getGlobalCommand($instance = null) public function getGlobalCommand($instance = null)
{ {
throw new ProgrammingError(getclass($this) . ' does not provide a global command'); throw new ProgrammingError(
'%s does not provide a global command',
getclass($this)
);
} }
} }

View File

@ -49,11 +49,9 @@ class LocalPipe implements Transport
$file->fflush(); $file->fflush();
} catch (Exception $e) { } catch (Exception $e) {
throw new ConfigurationError( throw new ConfigurationError(
sprintf(
'Could not open icinga command pipe at "%s" (%s)', 'Could not open icinga command pipe at "%s" (%s)',
$this->path, $this->path,
$e->getMessage() $e->getMessage()
)
); );
} }

View File

@ -246,7 +246,8 @@ class Reader implements IReader, Selectable
{ {
if (!is_readable($this->config->object_file)) { if (!is_readable($this->config->object_file)) {
throw new ConfigurationError( 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) { if (!$this->parser) {
@ -265,7 +266,8 @@ class Reader implements IReader, Selectable
{ {
if (!is_readable($this->config->status_file)) { if (!is_readable($this->config->status_file)) {
throw new ConfigurationError( 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) { if (!$this->parser) {

View File

@ -127,7 +127,8 @@ abstract class PreferencesStore
$storeClass = 'Icinga\\User\\Preferences\\Store\\' . $type . 'Store'; $storeClass = 'Icinga\\User\\Preferences\\Store\\' . $type . 'Store';
if (!class_exists($storeClass)) { if (!class_exists($storeClass)) {
throw new ConfigurationError( 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
); );
} }

View File

@ -78,7 +78,9 @@ class DbStore extends PreferencesStore
->fetchAll(); ->fetchAll();
} catch (Exception $e) { } catch (Exception $e) {
throw new NotReadableError( throw new NotReadableError(
'Cannot fetch preferences for user ' . $this->getUser()->getUsername() . ' from database', 0, $e 'Cannot fetch preferences for user %s from database',
$this->getUser()->getUsername(),
$e
); );
} }
@ -145,7 +147,9 @@ class DbStore extends PreferencesStore
} }
} catch (Exception $e) { } catch (Exception $e) {
throw new NotWritableError( throw new NotWritableError(
'Cannot insert preferences for user ' . $this->getUser()->getUsername() . ' into database', 0, $e 'Cannot insert preferences for user %s into database',
$this->getUser()->getUsername(),
$e
); );
} }
} }
@ -174,7 +178,9 @@ class DbStore extends PreferencesStore
} }
} catch (Exception $e) { } catch (Exception $e) {
throw new NotWritableError( throw new NotWritableError(
'Cannot update preferences for user ' . $this->getUser()->getUsername() . ' in database', 0, $e 'Cannot update preferences for user %s in database',
$this->getUser()->getUsername(),
$e
); );
} }
} }
@ -200,7 +206,9 @@ class DbStore extends PreferencesStore
); );
} catch (Exception $e) { } catch (Exception $e) {
throw new NotWritableError( throw new NotWritableError(
'Cannot delete preferences for user ' . $this->getUser()->getUsername() . ' from database', 0, $e 'Cannot delete preferences for user %s from database',
$this->getUser()->getUsername(),
$e
); );
} }
} }

View File

@ -62,8 +62,9 @@ class IniStore extends PreferencesStore
if (file_exists($this->preferencesFile)) { if (file_exists($this->preferencesFile)) {
if (!is_readable($this->preferencesFile)) { if (!is_readable($this->preferencesFile)) {
throw new NotReadableError( throw new NotReadableError(
'Preferences INI file ' . $this->preferencesFile . ' for user ' 'Preferences INI file %s for user %s is not readable',
. $this->getUser()->getUsername() . ' is not readable' $this->preferencesFile,
$this->getUser()->getUsername()
); );
} else { } else {
$this->preferences = parse_ini_file($this->preferencesFile); $this->preferences = parse_ini_file($this->preferencesFile);
@ -97,10 +98,8 @@ class IniStore extends PreferencesStore
if (!file_exists($this->preferencesFile)) { if (!file_exists($this->preferencesFile)) {
if (!is_writable($this->getStoreConfig()->location)) { if (!is_writable($this->getStoreConfig()->location)) {
throw new NotWritableError( throw new NotWritableError(
sprintf(
'Path to the preferences INI files %s is not writable', 'Path to the preferences INI files %s is not writable',
$this->getStoreConfig()->location $this->getStoreConfig()->location
)
); );
} }
@ -109,8 +108,9 @@ class IniStore extends PreferencesStore
if (!is_writable($this->preferencesFile)) { if (!is_writable($this->preferencesFile)) {
throw new NotWritableError( throw new NotWritableError(
'Preferences INI file ' . $this->preferencesFile . ' for user ' 'Preferences INI file %s for user %s is not writable',
. $this->getUser()->getUsername() . ' is not writable' $this->preferencesFile,
$this->getUser()->getUsername()
); );
} }

View File

@ -95,7 +95,10 @@ class Format
return '-'; return '-';
} }
if (! preg_match('~^\d+$~', $timestamp)) { if (! preg_match('~^\d+$~', $timestamp)) {
throw new ProgrammingError(sprintf('"%s" is not a number', $timestamp)); throw new ProgrammingError(
'"%s" is not a number',
$timestamp
);
} }
$prefix = ''; $prefix = '';
if ($diff < 0) { if ($diff < 0) {

View File

@ -369,8 +369,8 @@ class Form extends Zend_Form
$element->setAttrib('class', $class); $element->setAttrib('class', $class);
} else { } else {
throw new ProgrammingError( throw new ProgrammingError(
'You need to add the element "' . $elementName . '" to' . 'You need to add the element "%s" to the form before automatic submission can be enabled!',
' the form before automatic submission can be enabled!' $elementName
); );
} }
} }

View File

@ -117,11 +117,9 @@ class Hook
$base_class = self::$BASE_NS . ucfirst($name); $base_class = self::$BASE_NS . ucfirst($name);
if (!$instance instanceof $base_class) { if (!$instance instanceof $base_class) {
throw new ProgrammingError( throw new ProgrammingError(
sprintf(
'%s is not an instance of %s', '%s is not an instance of %s',
get_class($instance), get_class($instance),
$base_class $base_class
)
); );
} }
} }
@ -185,7 +183,10 @@ class Hook
public static function registerClass($name, $key, $class) public static function registerClass($name, $key, $class)
{ {
if (!class_exists($class)) { if (!class_exists($class)) {
throw new ProgrammingError('"' . $class . '" is not an existing class'); throw new ProgrammingError(
'"%s" is not an existing class',
$class
);
} }
if (!isset(self::$hooks[$name])) { if (!isset(self::$hooks[$name])) {
@ -207,7 +208,10 @@ class Hook
public static function registerObject($name, $key, $object) public static function registerObject($name, $key, $object)
{ {
if (!is_object($object)) { if (!is_object($object)) {
throw new ProgrammingError('"' . $object . '" is not an instantiated class'); throw new ProgrammingError(
'"%s" is not an instantiated class',
$object
);
} }
if (!isset(self::$instances[$name])) { if (!isset(self::$instances[$name])) {

View File

@ -456,7 +456,10 @@ class Menu implements RecursiveIterator
public function getSubMenu($id) public function getSubMenu($id)
{ {
if (false === $this->hasSubMenu($id)) { if (false === $this->hasSubMenu($id)) {
throw new ProgrammingError('Tried to get invalid sub menu "' . $id . '"'); throw new ProgrammingError(
'Tried to get invalid sub menu "%s"',
$id
);
} }
return $this->subMenus[$id]; return $this->subMenus[$id];

View File

@ -53,10 +53,8 @@ class Notification
) )
)) { )) {
throw new ProgrammingError( throw new ProgrammingError(
sprintf(
'"%s" is not a valid notification type', '"%s" is not a valid notification type',
$type $type
)
); );
} }

View File

@ -120,7 +120,10 @@ class Url
} }
if (!is_string($url)) { if (!is_string($url)) {
throw new ProgrammingError(sprintf('url "%s" is not a string', $url)); throw new ProgrammingError(
'url "%s" is not a string',
$url
);
} }
$urlObject = new Url(); $urlObject = new Url();

View File

@ -103,10 +103,8 @@ class View extends Zend_View_Abstract
{ {
if ($this->hasHelperFunction($name)) { if ($this->hasHelperFunction($name)) {
throw new ProgrammingError( throw new ProgrammingError(
sprintf(
'Cannot assign the same helper function twice: "%s"', 'Cannot assign the same helper function twice: "%s"',
$name $name
)
); );
} }

View File

@ -94,10 +94,10 @@ $this->addHelperFunction('attributeToString', function ($key, $value)
{ {
// TODO: Doublecheck this! // TODO: Doublecheck this!
if (! preg_match('~^[a-zA-Z0-9-]+$~', $key)) { if (! preg_match('~^[a-zA-Z0-9-]+$~', $key)) {
throw new ProgrammingError(sprintf( throw new ProgrammingError(
'Trying to set an invalid HTML attribute name: %s', 'Trying to set an invalid HTML attribute name: %s',
$key $key
)); );
} }
return sprintf( return sprintf(

View File

@ -38,10 +38,8 @@ class Widget
if (! class_exists($class)) { if (! class_exists($class)) {
throw new ProgrammingError( throw new ProgrammingError(
sprintf(
'There is no such widget: %s', 'There is no such widget: %s',
$name $name
)
); );
} }

View File

@ -52,11 +52,9 @@ abstract class AbstractWidget
} }
throw new ProgrammingError( throw new ProgrammingError(
sprintf(
'Trying to get invalid "%s" property for %s', 'Trying to get invalid "%s" property for %s',
$key, $key,
get_class($this) get_class($this)
)
); );
} }
@ -78,14 +76,12 @@ abstract class AbstractWidget
} }
throw new ProgrammingError( throw new ProgrammingError(
sprintf(
'Trying to set invalid "%s" property in %s. Allowed are: %s', 'Trying to set invalid "%s" property in %s. Allowed are: %s',
$key, $key,
get_class($this), get_class($this),
empty($this->properties) empty($this->properties)
? 'none' ? 'none'
: implode(', ', array_keys($this->properties)) : implode(', ', array_keys($this->properties))
)
); );
} }

View File

@ -274,7 +274,8 @@ class Dashboard extends AbstractWidget
{ {
if (! array_key_exists($name, $this->panes)) { if (! array_key_exists($name, $this->panes)) {
throw new ProgrammingError( throw new ProgrammingError(
sprintf('Trying to retrieve invalid dashboard pane "%s"', $name) 'Trying to retrieve invalid dashboard pane "%s"',
$name
); );
} }
return $this->panes[$name]; return $this->panes[$name];

View File

@ -105,7 +105,10 @@ class Pane extends AbstractWidget
if ($this->hasComponent($title)) { if ($this->hasComponent($title)) {
return $this->components[$title]; return $this->components[$title];
} }
throw new ProgrammingError(sprintf('Trying to access invalid component: %s', $title)); throw new ProgrammingError(
'Trying to access invalid component: %s',
$title
);
} }
/** /**
@ -157,7 +160,7 @@ class Pane extends AbstractWidget
} elseif (is_string($component) && $url !== null) { } elseif (is_string($component) && $url !== null) {
$this->components[$component] = new Component($component, $url, $this); $this->components[$component] = new Component($component, $url, $this);
} else { } else {
throw new ConfigurationError('Invalid component added: ' . $component); throw new ConfigurationError('Invalid component added: %s', $component);
} }
return $this; return $this;
} }

View File

@ -154,10 +154,8 @@ EOT;
{ {
if ($this->has($name)) { if ($this->has($name)) {
throw new ProgrammingError( throw new ProgrammingError(
sprintf(
'Cannot add a tab named "%s" twice"', 'Cannot add a tab named "%s" twice"',
$name $name
)
); );
} }
return $this->set($name, $tab); return $this->set($name, $tab);

View File

@ -114,7 +114,7 @@ class Monitoring_CommandController extends Controller
if ($targetConfig->get($instance)) { if ($targetConfig->get($instance)) {
$this->target = new CommandPipe($targetConfig->get($instance)); $this->target = new CommandPipe($targetConfig->get($instance));
} else { } else {
throw new ConfigurationError('Instance is not configured: '. $instance); throw new ConfigurationError('Instance is not configured: %s', $instance);
} }
} else { } else {
if ($targetConfig && $targetInfo = $targetConfig->current()) { if ($targetConfig && $targetInfo = $targetConfig->current()) {

View File

@ -87,12 +87,13 @@ class Backend implements Selectable, Queryable, ConnectionInterface
$backendConfig = $defaultBackend; $backendConfig = $defaultBackend;
} else { } else {
if (!array_key_exists($backendName, $allBackends)) { 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]; $backendConfig = $allBackends[$backendName];
if ((bool) $backendConfig->get('disabled', false)) { if ((bool) $backendConfig->get('disabled', false)) {
throw new ConfigurationError( throw new ConfigurationError(
'Configuration for backend ' . $backendName . ' available but backend is disabled' 'Configuration for backend %s available but backend is disabled',
$backendName
); );
} }
} }
@ -147,7 +148,10 @@ public function getResource()
{ {
$viewClass = '\\Icinga\\Module\\Monitoring\\DataView\\' . ucfirst($viewName); $viewClass = '\\Icinga\\Module\\Monitoring\\DataView\\' . ucfirst($viewName);
if (!class_exists($viewClass)) { if (!class_exists($viewClass)) {
throw new ProgrammingError('DataView ' . ucfirst($viewName) . ' does not exist'); throw new ProgrammingError(
'DataView %s does not exist',
ucfirst($viewName)
);
} }
return $viewClass; return $viewClass;
} }
@ -174,7 +178,9 @@ public function getResource()
. 'Query'; . 'Query';
if (!class_exists($queryClass)) { if (!class_exists($queryClass)) {
throw new ProgrammingError( throw new ProgrammingError(
'Query "' . ucfirst($queryName) . '" does not exist for backend ' . ucfirst($this->type) 'Query "%s" does not exist for backend %s',
ucfirst($queryName),
ucfirst($this->type)
); );
} }
return $queryClass; return $queryClass;

View File

@ -442,7 +442,11 @@ abstract class IdoQuery extends DbQuery
} elseif ($this->isCustomVar($alias)) { } elseif ($this->isCustomVar($alias)) {
$this->requireCustomvar($alias); $this->requireCustomvar($alias);
} else { } else {
throw new ProgrammingError(sprintf('%s : Got invalid column: %s', get_called_class(), $alias)); throw new ProgrammingError(
'%s : Got invalid column: %s',
get_called_class(),
$alias
);
} }
return $this; return $this;
} }
@ -476,7 +480,8 @@ abstract class IdoQuery extends DbQuery
{ {
if ($this->hasJoinedVirtualTable($name)) { if ($this->hasJoinedVirtualTable($name)) {
throw new ProgrammingError( throw new ProgrammingError(
sprintf('IDO query virtual table conflict with "%s"', $name) 'IDO query virtual table conflict with "%s"',
$name
); );
} }
return $this; return $this;
@ -499,10 +504,8 @@ abstract class IdoQuery extends DbQuery
$this->$func(); $this->$func();
} else { } else {
throw new ProgrammingError( throw new ProgrammingError(
sprintf(
'Cannot join "%s", no such table found', 'Cannot join "%s", no such table found',
$table $table
)
); );
} }
$this->joinedVirtualTables[$table] = true; $this->joinedVirtualTables[$table] = true;
@ -581,10 +584,8 @@ abstract class IdoQuery extends DbQuery
// TODO: Improve this: // TODO: Improve this:
if (! preg_match('~^_(host|service)_([a-zA-Z0-9_]+)$~', $customvar, $m)) { if (! preg_match('~^_(host|service)_([a-zA-Z0-9_]+)$~', $customvar, $m)) {
throw new ProgrammingError( throw new ProgrammingError(
sprintf(
'Got invalid custom var: "%s"', 'Got invalid custom var: "%s"',
$customvar $customvar
)
); );
} }
return array($m[1], $m[2]); return array($m[1], $m[2]);

View File

@ -79,7 +79,9 @@ class TimeEntry
$entry->{$methodName}($value); $entry->{$methodName}($value);
} else { } else {
throw new ProgrammingError( throw new ProgrammingError(
'Method "' . $methodName . '" does not exist on object of type "' . __CLASS__ . '"' 'Method "%s" does not exist on object of type "%s"',
$methodName,
__CLASS__
); );
} }
} }