Return false from isSupported() when the output modality has no matching capability - #271
Conversation
isSupported() is declared to return bool, but the RuntimeException from inferCapabilityFromOutputModalities() propagated out of it when the configured output modality had no matching capability. generateResult() still throws for the same modality, which is the behaviour testGenerateResultThrowsExceptionForUnsupportedOutputModality asserts. Fixes WordPress#270
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #271 +/- ##
=========================================
Coverage 86.49% 86.50%
- Complexity 1327 1328 +1
=========================================
Files 68 68
Lines 4295 4297 +2
=========================================
+ Hits 3715 3717 +2
Misses 580 580
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Fixes #270
isSupported()is declared: bool, but theRuntimeExceptionfrominferCapabilityFromOutputModalities()propagates straight out of it when the configured output modality has no matching capability.ModalityEnum::document()is the reachable case, sinceDOCUMENTis a first class modality butCapabilityEnumhas nothing to map it to.This catches that one call and returns
false. Asking whether an unsupported modality is supported has a correct answer, and it is no.Two things kept deliberately narrow:
generateResult()is untouched and still throws for the same modality. That is the right behaviour there, andtestGenerateResultThrowsExceptionForUnsupportedOutputModality()asserts it.try, so aRuntimeExceptionraised anywhere else inisSupported()still propagates.I also considered changing
inferCapabilityFromOutputModalities()to return?CapabilityEnumand letting each caller decide, which reads a little cleaner, but it changes a shared private method used by the generation path as well. Happy to redo it that way if you would rather.Testing
testIsSupportedReturnsFalseForUnsupportedOutputModality()fails on trunk with:and passes with the patch. Full unit suite green at 1165 tests, 4261 assertions.
phpcsandphpstanboth clean.I did not add an
@sinceline to the docblock since I do not know which version this would land in. Say the word and I will add it.I checked the open PRs that touch nearby code and there is no overlap. #222 adds
isSupportedForSoundGeneration(), which passes an explicit capability and never reaches the inference branch, and #254 changesModelResolver::isSupported(), which is a different method.