-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try Catch for embeded media #9424
Conversation
$attr = array( | ||
'class' => 'ss-media-exception embed' | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$attr = array( | |
'class' => 'ss-media-exception embed' | |
); | |
$attr = [ | |
'class' => 'ss-media-exception embed' | |
]; |
$result = HTML::createTag( | ||
'div', | ||
$attr, | ||
HTML::createTag('p', array(), 'There was a problem loading the media.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If changing to the [] format from array() in @ScopeyNZ s suggestion, then probably should do the same here.
HTML::createTag('p', array(), 'There was a problem loading the media.') | |
HTML::createTag('p', [], 'There was a problem loading the media.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the text be translateable?
https://docs.silverstripe.org/en/4/developer_guides/i18n/
HTML::createTag('p', array(), 'There was a problem loading the media.') | |
HTML::createTag('p', [], _t("Namespace.Entity", "There was a problem loading the media"); |
@ScopeyNZ - can you advise what the namespace & entity should be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Normally the namespace is related to the class (and namespace) - the "entity" indicates the content of the message. Maybe something like EmbedShortcodeProvider.INVALID_URL
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EmbedShortcodeProvider.INVALID_URL works for me : )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be _t(__CLASS__ . '.INVALID_URL', 'There was a problem loading the media.')
so we get the fully qualified class name, that’s the convention across core code 😄
$embed = $embed->getEmbed(); | ||
try { | ||
$embed = $embed->getEmbed(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
travis is failing because:
94 | ERROR | [x] Expected 1 space after closing brace; newline found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think the style is supposed to be:
} | |
try { | |
$embed = $embed->getEmbed(); | |
} catch(\Embed\Exceptions\InvalidUrlException $e) { |
try { | ||
$embed = $embed->getEmbed(); | ||
} | ||
catch(\Embed\Exceptions\InvalidUrlException $e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
95 | ERROR | [x] Expected 1 space(s) after CATCH keyword; 0 found
catch(\Embed\Exceptions\InvalidUrlException $e) { | |
catch (\Embed\Exceptions\InvalidUrlException $e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change this to
use \Embed\Exceptions\InvalidUrlException;
(top of the php file)
catch (InvalidUrlException $e) {
scrutinizer is flagging a decrease in quality, complaining that this can't be found: SilverStripe\View\Shortcodes\Director for php 7.1. Am I reading that right? it has a tick, but an F sounds pretty bad. @rdigitalg have you tested against php 7.1 ? |
@asecondwill I think it’s because it’s currently missing the namespace import |
only tested on php 7.0, ill run tests on other versions and report back |
Thanks for changes @rdigitalg , @ScopeyNZ @kinglozzer @emteknetnz : How is this looking now? |
@kinglozzer - is this likely to get merged do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m fine with merging this. I know that adding caching is mentioned in #9073, but no one has actually submitted a PR for that and this certainly doesn’t block that work
Hey @asecondwill, sorry this is taking a while to get across the line! If you could squash your commits and give them a message matching our standard format - something like “FIX Handle failures in embedded media gracefully” - I’d be happy to merge this for you 🙂 |
Would be great if this could get merged in. Spent the morning fixing older blog posts containing broken GIFs that were bringing down a site's blog entirely. |
Co-authored-by: Loz Calver <[email protected]>
Hi, what are the chances of cherry picking this fix back to the |
* Try Catch for embeded media * added missing namespaces, translatable message INVALID_URL * generate tag only once * catch after closing bracket * space after comma * Update src/View/Shortcodes/EmbedShortcodeProvider.php * Linting Co-authored-by: [email protected] <[email protected]> Co-authored-by: Steve Boyd <[email protected]> Co-authored-by: Loz Calver <[email protected]>
@brynwhyman |
Thanks for merging this in, Ill test it this week on our site. |
Same, thank you all!! <3 |
BUG Embedded media throws E_EMERGENCY error if url returns status codes other than 200.
If a media that is already embedded on the page from a url is removed from the server/url it throws an E_EMERGENCY error that breaks the whole page. Added a try / catch block to EmbedShortcodeProvider.php in function handle_shortcode() that will prevent this and just give a message based on the environment.
Dev environment will display the response message from the url.
Live environment will just display the text 'There was a problem loading the media.'
The text is wrapped in a div that has the class ss-media-exception so it can be styled by admin.