Restore unreachable error handling when plugin::byId can't find a plugin - #3455
Open
Salvialf wants to merge 2 commits into
Open
Restore unreachable error handling when plugin::byId can't find a plugin#3455Salvialf wants to merge 2 commits into
Salvialf wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
plugin::byId()is the onlybyId()method in the entirecore/class/directory that throws an exception instead of returning a falsy value when nothing is found (verified against all 27 otherbyId()implementations, which are plain DB lookups). Several call sites acrosscorewere written assuming the more common convention, guarding the result withif (!is_object($plugin)). SincebyId()throws before ever returning, these guards were dead code, and the intended fallback behavior (a friendly error message, a graceful "not found" response, skipping one entry in a loop) was never reachable.plugin::byId()in atry/catch(or, inutils.inc.php's loop over multiple plugins, aplugin::isInstalled()pre-check), restoring the originally intended fallback behavior instead of letting a generic exception propagate to the nearest outer handler.core/ajax/plugin.ajax.php, also removed two$plugin_id = init('id')assignments left unused ingetDeamonInfoanddeamonStart, found while touching these same blocks.jsonrpc::makeError()andjsonrpc::makeSuccess()are now documented with@return never, mirroringajax::success()/ajax::error()'s existing annotations. Without it, PHPStan flagged$pluginas possibly undefined after thetry/catchblocks incore/api/jeeApi.php, since it couldn't infer that thecatchbranch's call tomakeSuccess()always ends execution.