Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#3502 - CiviEventDispatcher - Softer errors for not-ready. More comments. #23785

Merged
merged 2 commits into from
Jun 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Civi/Core/CiviEventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,18 @@ 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`.

// 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).");
Expand Down