Skip to content

Commit 6f44fb1

Browse files
committed
Catch \Throwable when utilizing hooks
Hooks shouldn't be able to fatally end execution.
1 parent 5058b41 commit 6f44fb1

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

library/Icingadb/Hook/ActionsHook/ObjectActionsHook.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Icinga\Module\Icingadb\Hook\ActionsHook;
66

7-
use Exception;
87
use Icinga\Application\Hook;
98
use Icinga\Application\Logger;
109
use Icinga\Exception\IcingaException;
@@ -20,6 +19,7 @@
2019
use ipl\Html\Text;
2120
use ipl\Orm\Model;
2221
use ipl\Web\Widget\Link;
22+
use Throwable;
2323

2424
use function ipl\Stdlib\get_php_type;
2525

@@ -72,7 +72,7 @@ final public static function loadActions(Model $object): HtmlElement
7272
'data-icinga-module' => $moduleName
7373
]), HtmlString::create($renderedLink)));
7474
}
75-
} catch (Exception $e) {
75+
} catch (Throwable $e) {
7676
Logger::error("Failed to load object actions: %s\n%s", $e, $e->getTraceAsString());
7777
$list->addHtml(new HtmlElement('li', null, Text::create(IcingaException::describe($e))));
7878
}

library/Icingadb/Hook/CustomVarRendererHook.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
namespace Icinga\Module\Icingadb\Hook;
66

77
use Closure;
8-
use Exception;
98
use Icinga\Application\Hook;
109
use Icinga\Application\Logger;
1110
use Icinga\Module\Icingadb\Hook\Common\HookUtils;
1211
use ipl\Orm\Model;
12+
use Throwable;
1313

1414
abstract class CustomVarRendererHook
1515
{
@@ -68,7 +68,7 @@ final public static function prepareForObject(Model $object): Closure
6868
if ($hook->prefetchForObject($object)) {
6969
$hooks[] = $hook;
7070
}
71-
} catch (Exception $e) {
71+
} catch (Throwable $e) {
7272
Logger::error('Failed to load hook %s:', get_class($hook), $e);
7373
}
7474
}
@@ -84,7 +84,7 @@ final public static function prepareForObject(Model $object): Closure
8484
$renderedKey = $hook->renderCustomVarKey($key);
8585
$renderedValue = $hook->renderCustomVarValue($key, $value);
8686
$group = $hook->identifyCustomVarGroup($key);
87-
} catch (Exception $e) {
87+
} catch (Throwable $e) {
8888
Logger::error('Failed to use hook %s:', get_class($hook), $e);
8989
continue;
9090
}

library/Icingadb/Hook/ExtensionHook/ObjectDetailExtensionHook.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Icinga\Module\Icingadb\Hook\ExtensionHook;
66

7-
use Exception;
87
use Icinga\Application\Hook;
98
use Icinga\Application\Logger;
109
use Icinga\Exception\IcingaException;
@@ -25,6 +24,7 @@
2524
use ipl\Html\Text;
2625
use ipl\Html\ValidHtml;
2726
use ipl\Orm\Model;
27+
use Throwable;
2828

2929
use function ipl\Stdlib\get_php_type;
3030

@@ -110,7 +110,7 @@ final public static function loadExtensions(Model $object): array
110110
]),
111111
HtmlString::create($extension)
112112
);
113-
} catch (Exception $e) {
113+
} catch (Throwable $e) {
114114
Logger::error("Failed to load detail extension: %s\n%s", $e, $e->getTraceAsString());
115115
$extensions[$location] = Text::create(IcingaException::describe($e));
116116
}

library/Icingadb/Hook/ExtensionHook/ObjectsDetailExtensionHook.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Icinga\Module\Icingadb\Hook\ExtensionHook;
66

7-
use Exception;
87
use Icinga\Application\Hook;
98
use Icinga\Application\Logger;
109
use Icinga\Exception\IcingaException;
@@ -19,6 +18,7 @@
1918
use ipl\Orm\Query;
2019
use ipl\Stdlib\BaseFilter;
2120
use ipl\Stdlib\Filter;
21+
use Throwable;
2222

2323
abstract class ObjectsDetailExtensionHook extends BaseExtensionHook
2424
{
@@ -90,7 +90,7 @@ final public static function loadExtensions(string $objectType, Query $query, Fi
9090
]),
9191
HtmlString::create($extension)
9292
);
93-
} catch (Exception $e) {
93+
} catch (Throwable $e) {
9494
Logger::error("Failed to load details extension: %s\n%s", $e, $e->getTraceAsString());
9595
$extensions[$location] = Text::create(IcingaException::describe($e));
9696
}

library/Icingadb/Hook/PluginOutputHook.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Icinga\Module\Icingadb\Hook;
66

7-
use Exception;
87
use Icinga\Application\Hook;
98
use Icinga\Application\Logger;
109
use Icinga\Module\Icingadb\Hook\Common\HookUtils;
10+
use Throwable;
1111

1212
abstract class PluginOutputHook
1313
{
@@ -53,7 +53,7 @@ final public static function processOutput(string $output, string $commandName,
5353
if ($hook->isSupportedCommand($commandName)) {
5454
$output = $hook->render($output, $commandName, $enrichOutput);
5555
}
56-
} catch (Exception $e) {
56+
} catch (Throwable $e) {
5757
Logger::error("Unable to process plugin output: %s\n%s", $e, $e->getTraceAsString());
5858
}
5959
}

library/Icingadb/Hook/TabHook/HookActions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
namespace Icinga\Module\Icingadb\Hook\TabHook;
66

7-
use Exception;
87
use Generator;
98
use Icinga\Application\Hook;
109
use Icinga\Application\Logger;
1110
use Icinga\Module\Icingadb\Hook\TabHook;
1211
use ipl\Html\ValidHtml;
1312
use ipl\Orm\Model;
1413
use ipl\Stdlib\Str;
14+
use Throwable;
1515

1616
/**
1717
* Trait HookActions
@@ -78,7 +78,7 @@ protected function loadTabHooks(): array
7878
if ($hook->shouldBeShown($this->objectToLoadTabsFor)) {
7979
$this->tabHooks[Str::camel($hook->getName())] = $hook;
8080
}
81-
} catch (Exception $e) {
81+
} catch (Throwable $e) {
8282
Logger::error("Failed to load tab hook: %s\n%s", $e, $e->getTraceAsString());
8383
}
8484
}

library/Icingadb/Widget/Detail/ObjectDetail.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Icinga\Module\Icingadb\Widget\Detail;
66

7-
use Exception;
87
use Icinga\Application\ClassLoader;
98
use Icinga\Application\Config;
109
use Icinga\Application\Hook;
@@ -53,6 +52,7 @@
5352
use ipl\Stdlib\Filter;
5453
use ipl\Web\Widget\Icon;
5554
use ipl\Web\Widget\StateBall;
55+
use Throwable;
5656

5757
class ObjectDetail extends BaseHtmlElement
5858
{
@@ -172,7 +172,7 @@ protected function createActions()
172172
if (! isset($nativeExtensionProviders[$moduleName])) {
173173
try {
174174
$navigation->merge($hook->getNavigation($this->compatObject()));
175-
} catch (Exception $e) {
175+
} catch (Throwable $e) {
176176
Logger::error("Failed to load legacy action hook: %s\n%s", $e, $e->getTraceAsString());
177177
$navigation->addItem($moduleName, ['label' => IcingaException::describe($e), 'url' => '#']);
178178
}
@@ -475,7 +475,7 @@ protected function createExtensions(): array
475475

476476
try {
477477
$graph = HtmlString::create($grapher->getPreviewHtml($this->compatObject()));
478-
} catch (Exception $e) {
478+
} catch (Throwable $e) {
479479
Logger::error("Failed to load legacy grapher: %s\n%s", $e, $e->getTraceAsString());
480480
$graph = Text::create(IcingaException::describe($e));
481481
}
@@ -511,7 +511,7 @@ protected function createExtensions(): array
511511
]),
512512
HtmlString::create($renderedExtension)
513513
);
514-
} catch (Exception $e) {
514+
} catch (Throwable $e) {
515515
Logger::error("Failed to load legacy detail extension: %s\n%s", $e, $e->getTraceAsString());
516516
$extensionHtml = Text::create(IcingaException::describe($e));
517517
}

0 commit comments

Comments
 (0)