ProgrammingError: extend IcingaException

refs #6931
This commit is contained in:
Alexander Klimov 2014-08-26 11:15:19 +02:00
parent 7074fa1331
commit febb2d1ae2
23 changed files with 107 additions and 80 deletions

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

@ -323,10 +323,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
)
); );
} }
@ -392,10 +390,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

@ -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

@ -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
); );
} }
} }
@ -188,7 +192,7 @@ abstract class Filter
$args = $args[0]; $args = $args[0];
} }
} }
if (count($args) > 1) { if (count($args) > 1) {
return new FilterNot(array(new FilterAnd($args))); return new FilterNot(array(new FilterAnd($args)));
} else { } else {
return new FilterNot($args); return new FilterNot($args);
@ -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

@ -78,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'
); );
} }
} }

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

@ -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

@ -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

@ -277,7 +277,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

@ -224,7 +224,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
);
} }
/** /**

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

@ -148,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;
} }
@ -175,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__
); );
} }
} }