I was baffled by a whitescreen when I enabled a module that I was working on. My php error log told me:
Call to undefined function entity_crud_get_info() in /home/chris/projects/bathroom-city/sites/all/modules/entity/entity.rules.inc on line 96
(entity_crud_get_info() is defined in entity.module)
A stacktrace told me the error was coming from _drupal_error_handler() >> _drupal_error_handler_real() >> _drupal_log_error() >> watchdog(), which was invoking hook_watchdog to get to rules_watchdog() >> rules_invoke_event('watchdog') >> rules_get_cache() >> RulesEventSet::rebuildEventCache() >> rules_fetch_data('event_info'), invoking hook_rules_event_info to get entity_rules_event_info()
In other words, the error was occuring within the error handler.
The error handler was handling an error raised during drupal_bootstrap() >> _drupal_bootstrap_full() >> module_load_all() >> drupal_load()
(This error turned out to be an incorrect filename in an include_once() in my .module file. But that's not directly relevant to this bug report.)
So as far as I can tell, drupal had loaded some but not all of the modules when the initial error occured; then as part of the error handling, it invoked a rule, part of which was defined in the entity module. But the entity module itself had not loaded by this point, even though the rule definition which pointed to entity.rules.inc was present (maybe just in the cache? although I tried clearing all caches and it didn't fix the problem.) And so handling the rule caused this second error.
I can see a number of possible solutions here, although not necessarily within the purview of the rules module.
- Change the behaviour of watchdog() during module_load_all so as not to invoke hook_watchdog
- Change the behaviour of rules_invoke_event during bootstrap to be more careful about what rules/modules to invoke
- Change the behaviour of rules_invoke_event generally so that it checks whether a module has actually been loaded before it fires one of its events