diff options
author | Alexandre Alapetite <alexandre@alapetite.fr> | 2025-04-01 17:55:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-01 17:55:20 +0200 |
commit | 3336631a846c2e34f55b2ecb76b46cd68228486f (patch) | |
tree | c2672609f84d57c1bf7c3c338a1369ff5748bff0 | |
parent | dbdadbb4107878d9233f635c31a88afe45957101 (diff) | |
download | freshrss-3336631a846c2e34f55b2ecb76b46cd68228486f.tar.gz freshrss-3336631a846c2e34f55b2ecb76b46cd68228486f.zip |
Catch extension exceptions in override (#7475)
* Catch extension exceptions in override
https://github.com/FreshRSS/Extensions/pull/300#issuecomment-2768578464
* Fix error message
-rw-r--r-- | app/Controllers/extensionController.php | 7 | ||||
-rw-r--r-- | lib/Minz/Extension.php | 6 | ||||
-rw-r--r-- | lib/Minz/ExtensionManager.php | 8 |
3 files changed, 19 insertions, 2 deletions
diff --git a/app/Controllers/extensionController.php b/app/Controllers/extensionController.php index eb2c3f8d8..f08013e7d 100644 --- a/app/Controllers/extensionController.php +++ b/app/Controllers/extensionController.php @@ -131,7 +131,12 @@ class FreshRSS_extension_Controller extends FreshRSS_ActionController { FreshRSS_View::prependTitle($ext->getName() . ' · ' . _t('admin.extensions.title') . ' · '); $this->view->extension = $ext; - $this->view->extension->handleConfigureAction(); + try { + $this->view->extension->handleConfigureAction(); + } catch (Minz_Exception $e) { // @phpstan-ignore catch.neverThrown (Thrown by extensions) + Minz_Log::error('Error while configuring extension ' . $ext->getName() . ': ' . $e->getMessage()); + Minz_Request::bad(_t('feedback.extensions.enable.ko', $ext_name, _url('index', 'logs')), ['c' => 'extension', 'a' => 'index']); + } } /** diff --git a/lib/Minz/Extension.php b/lib/Minz/Extension.php index 25cbe2091..d03db8bde 100644 --- a/lib/Minz/Extension.php +++ b/lib/Minz/Extension.php @@ -91,6 +91,10 @@ abstract class Minz_Extension { $this->is_enabled = true; } + final public function disable(): void { + $this->is_enabled = false; + } + /** * Return if the extension is currently enabled. * @@ -253,6 +257,8 @@ abstract class Minz_Extension { switch ($type) { case 'system': return FreshRSS_Context::hasSystemConf(); case 'user': return FreshRSS_Context::hasUserConf(); + default: + return false; } } diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php index 84a6fc09f..fea1f5879 100644 --- a/lib/Minz/ExtensionManager.php +++ b/lib/Minz/ExtensionManager.php @@ -268,7 +268,13 @@ final class Minz_ExtensionManager { spl_autoload_register([$ext, 'autoload']); } $ext->enable(); - $ext->init(); + try { + $ext->init(); + } catch (Minz_Exception $e) { // @phpstan-ignore catch.neverThrown (Thrown by extensions) + Minz_Log::warning('Error while enabling extension ' . $ext->getName() . ': ' . $e->getMessage()); + $ext->disable(); + unset(self::$ext_list_enabled[$ext_name]); + } } } |