Page MenuHomePhabricator

Hook functions should not be required to return a value
Closed, ResolvedPublic

Description

When a hook neglects to return a value, Hooks::run throws an MWException with the message "Detected bug in an extension! Hook $func failed to return a value; should return true to continue hook processing or false to abort."

This is a frustrating gotcha that has caused us some serious in the past (see T51727; bug 49727 for a recent example). Most hook handlers are written with the intent of complementing or augmenting core functionality rather than vetoing it, making it quite natural for a developer to forget that the caller is waiting for permission to proceed. The potential for confusion is magnified by the fact that DOM event handlers and jQuery event handlers are not required to return an explicit value for the handled event to continue propagating.

We should tolerate implicit and explicit null return values from hook handlers. Making this change should not break anything, as any hook handler currently returning null is treated as an error.


Version: 1.22.0
Severity: normal

Details

Reference
bz50134

Event Timeline

bzimport raised the priority of this task from to Normal.Nov 22 2014, 2:00 AM
bzimport added a project: MediaWiki-General.
bzimport set Reference to bz50134.
ori created this task.Jun 24 2013, 9:41 PM

Related URL: https://gerrit.wikimedia.org/r/70328 (Gerrit Change I11deb2117ff9233c77868470f50e0d8f74053545)

It should be noted that this originally was an intentional change, committed by Brion in r23133 (see http://www.mediawiki.org/wiki/Special:Code/MediaWiki/23133) on 20 June 2007.

ori added a comment.Jun 25 2013, 9:24 PM

Jack, thanks very much for tracking that down.