silverstripe / silverstripe-assets

Silverstripe Assets component
BSD 3-Clause "New" or "Revised" License
9 stars 65 forks source link

Error when previewing page and asset doesn't exist #545

Closed phptek closed 12 months ago

phptek commented 1 year ago

"[Emergency] Uncaught TypeError: Return value of SilverStripe\Assets\Shortcodes\FileShortcodeProvider::getCachedMarkup() must be of the type string, null returned"

Granted, this is a feature of silverstripe/cms, however the culprit is logic found in silverstripe/assets, specifically in FileShortcodeProvider::getCachedMarkup()

return $item['markup']; <-- can return null. A simple null coalesce operator "fixes" it ala return $item['markup'] ?? '', but there may be issues in silverstripe/cms or silverstripe/framework where this array value should never be null. I think this has just surfaced when an explicit :string return type was naively added to the method.

Using Silverstripe 4.12.3 on PHP 7.4

PR

GuySartorelli commented 1 year ago

Thanks for reporting this. Can you please give a clear set of steps to reproduce this error? You mention previewing a page when an asset doesn't exist - but you haven't described for example how the asset relates to the page?

GuySartorelli commented 12 months ago

PR merged and tagged as 1.13.3 and 2.0.4