From b589fcbdb5596dfd613a0f924372e2bbf6d2095c Mon Sep 17 00:00:00 2001 From: maxpozdeev Date: Mon, 12 May 2025 15:22:34 +0300 Subject: [PATCH] use MTTExtensionLoaderException while loading extensions --- src/includes/classes.php | 9 +++++---- src/init.php | 8 +++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/includes/classes.php b/src/includes/classes.php index a5f70bd..5878cde 100644 --- a/src/includes/classes.php +++ b/src/includes/classes.php @@ -154,6 +154,7 @@ interface MTTExtensionSettingsInterface function saveSettings(array $array, ?string &$outMesssage): bool; } +class MTTExtensionLoaderException extends Exception {} class MTTExtensionLoader { @@ -181,20 +182,20 @@ class MTTExtensionLoader $instanceFunc = 'mtt_ext_'. $extNormalized. '_instance'; if (!function_exists($instanceFunc)) { - throw new Exception("Failed to init extension '$ext': no '$instanceFunc' function"); + throw new MTTExtensionLoaderException("Failed to init extension '$ext': no '$instanceFunc' function"); } $instance = $instanceFunc(); if ( ! ($instance instanceof MTTExtension) ) { - throw new Exception("Failed to init extension '$ext': incompatible instance"); + throw new MTTExtensionLoaderException("Failed to init extension '$ext': incompatible instance"); } $className = get_class($instance); if (!defined("$className::bundleId")) { - throw new Exception("Failed to load extension '$ext': missing required class constants (bundleId)"); + throw new MTTExtensionLoaderException("Failed to load extension '$ext': missing required class constants (bundleId)"); } if ($instance::bundleId != $ext) { - throw new Exception("Failed to load extension '$ext': bundleId does not conforms to extension dir"); + throw new MTTExtensionLoaderException("Failed to load extension '$ext': bundleId does not conforms to extension dir"); } Lang::instance()->loadExtensionLang($ext); diff --git a/src/init.php b/src/init.php index a2e3d2d..fbfbd39 100644 --- a/src/init.php +++ b/src/init.php @@ -470,9 +470,15 @@ function loadExtensions() try { MTTExtensionLoader::loadExtension($ext); } - catch (Exception $e) { + catch (MTTExtensionLoaderException $e) { error_log($e->getMessage()); } + catch (Exception $e) { + if (MTT_DEBUG) + throw $e; + else + error_log("Error while loading extension '$ext': ". $e->getMessage()); + } } }