From 19000309126336390219130ab20f3b558742837c Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 8 Jun 2022 19:14:04 -0700 Subject: [PATCH 1/2] dev/core#3502 - CiviEventDispatcher - Tweak error message. Add explanation. --- Civi/Core/CiviEventDispatcher.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Civi/Core/CiviEventDispatcher.php b/Civi/Core/CiviEventDispatcher.php index f2ddb6431ef6..14f944df2f4e 100644 --- a/Civi/Core/CiviEventDispatcher.php +++ b/Civi/Core/CiviEventDispatcher.php @@ -187,7 +187,13 @@ public function dispatch($eventName, Event $event = NULL) { throw new \RuntimeException("The dispatch policy prohibits event \"$eventName\"."); case 'not-ready': - throw new \RuntimeException("CiviCRM has not bootstrapped sufficiently to fire event \"$eventName\"."); + // The system is not ready to run hooks -- eg it has not finished loading the extension main-files. + // If you fire a hook at this point, it will not be received by the intended listeners. + // In practice, many hooks involve cached data-structures, so a premature hook is liable to have spooky side-effects. + // This condition indicates a structural problem and merits a consistent failure-mode. + // If you believe some special case merits an exemption, then you could add it to `$bootDispatchPolicy`. + + throw new \RuntimeException("The event \"$eventName\" attempted to fire before CiviCRM was fully loaded. Skipping."); default: throw new \RuntimeException("The dispatch policy for \"$eventName\" is unrecognized ($mode)."); From f3ec3f9e77da68f1fbb8bc88ff6a5c172b3dc0ba Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 8 Jun 2022 21:17:51 -0700 Subject: [PATCH 2/2] dev/core#3502 - CiviEventDispatcher - Tune down the warning --- Civi/Core/CiviEventDispatcher.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Civi/Core/CiviEventDispatcher.php b/Civi/Core/CiviEventDispatcher.php index 14f944df2f4e..d4564e5b4c25 100644 --- a/Civi/Core/CiviEventDispatcher.php +++ b/Civi/Core/CiviEventDispatcher.php @@ -193,7 +193,12 @@ public function dispatch($eventName, Event $event = NULL) { // This condition indicates a structural problem and merits a consistent failure-mode. // If you believe some special case merits an exemption, then you could add it to `$bootDispatchPolicy`. - throw new \RuntimeException("The event \"$eventName\" attempted to fire before CiviCRM was fully loaded. Skipping."); + // An `Exception` would be ideal for preventing new bugs, but it can be too noisy for systems with pre-existing bugs. + // throw new \RuntimeException("The event \"$eventName\" attempted to fire before CiviCRM was fully loaded. Skipping."); + // Complain to web-user and sysadmin. Log a backtrace. We're pre-boot, so don't use high-level services. + error_log("The event \"$eventName\" attempted to fire before CiviCRM was fully loaded. Skipping.\n" . \CRM_Core_Error::formatBacktrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), FALSE)); + trigger_error("The event \"$eventName\" attempted to fire before CiviCRM was fully loaded. Skipping.", E_USER_WARNING); + return $event; default: throw new \RuntimeException("The dispatch policy for \"$eventName\" is unrecognized ($mode).");