Page MenuHomePhabricator

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


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



Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 2:00 AM
bzimport set Reference to bz50134.

Related URL: (Gerrit Change I11deb2117ff9233c77868470f50e0d8f74053545)

It should be noted that this originally was an intentional change, committed by Brion in r23133 (see on 20 June 2007.

Jack, thanks very much for tracking that down.