Repository navigation
Conversation
ImageRuntime::getImageVariation() catches variation errors, logs them and returns `new Variation()`. Since Ibexa 5 the properties of Variation are typed, so reading any of them on that object throws "Typed property ... must not be accessed before initialization". A template like `ng_image_alias(field, 'large').uri` therefore fails with an Error for a single missing or broken image, and takes the whole page down with a 500, also in prod where strict_variables is off. Return a Variation with all properties initialized to empty values, so templates render an empty value again, as they did before Ibexa 5, while the error is still logged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
ImageRuntime::getImageVariation()(behindng_image_alias()) catchesInvalidVariationException,SourceImageNotFoundExceptionandInvalidArgumentException, logs the error and returnsnew Variation().Since Ibexa 5 the properties of
Ibexa\Contracts\Core\Variation\Values\Variationare typed (protected string $uri, ...) and are not initialized on a barenew Variation(). Reading any of them throws:So the common template pattern
fails for a single missing or broken image, and the whole page returns a 500. The fallback was meant to prevent exactly that, and it did until Ibexa 4, where the properties were untyped and read as
null.Two details make this hard to guard against in templates:
Error, not a Twig error, so it also happens in prod withstrict_variablesoff.ValueObject::__isset()only checksproperty_exists(), so?? ''andis defineddo not help.We hit it on a Media Site based project (Ibexa 5.0, Site API 7.0.3). One logo image failed to resolve and the homepage went down. The Media Site templates use this pattern in many places (hero, about, full views, gallery grid).
Fix
Return a
Variationwith all properties initialized to empty values (uri,fileName,dirPathandmimeTypeset to'',fileSizeto0,lastModifiedto the Unix epoch). Templates render an empty value again, as before Ibexa 5, and the error is still logged. The return type and the public API do not change.I chose this over returning
null(like Ibexa's ownibexa_image_alias()) becausenullwould change the method's contract. Withstrict_variableson, it would also turn everyng_image_alias(...).uriin dev into a Twig error.Tests
ImageRuntimeTestis new, as there was no test forImageRuntimebefore. It covers:Variationproperty can be readThe failure cases fail on
masterwith the error above and pass with this change. The full unit suite passes (808 tests). The one deprecation in the suite also appears onmaster.I also checked it end to end on the project: with a source image missing, the page returned 500 before and 200 after.
🤖 Generated with Claude Code