Problem/Motivation
There are several places in the oEmbed API that handle errors that may occur during the process of fetching or otherwise interacting with oEmbed resources, and these errors are either not logged at all, or logged in very general terms that will not help with troubleshooting. We should revisit these areas and improve the error handling.
This issue is spun off from #2831944-237: Implement media source plugin for remote video via oEmbed, point #1.
Steps to reproduce
OEmbed errors occur in certain circumstances, such as when a use created a remote video media entity referring to a video which is restricted or otherwise not publicly accessible, or when the host of the video is not accessible.
Proposed resolution
- improve error messages logged so that the details of the failure can be better investigated
- improve feedback surfaced to the user (suggested in #28 here)
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-2972846
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
phenaproximaThe main issue is in.
Comment #4
rogerpfaffDoes this include not completely shut down the site if network connection is bad or the oEmbed service (url) is not available? I see no reason to break stuff instead of returning an error informing about that situation.
Comment #6
phenaproximaComment #9
phenaproximaComment #11
RoSk0First draft.
Feedback welcome.
Comment #12
RoSk0Found another place for improvement. See interdiff.
Comment #13
RoSk0To be clear about addition: without it in the locked environment where Drupal talks to the world via proxy and resource destination domain is not allowed you will see this in log for media "cURL error 56: Received HTTP code 403 from proxy after CONNECT (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)". Not helpful at all, but with the request URI you will be clear about what was the request for.
Comment #14
RoSk0Re-roll of #12 for 9.1.x.
Comment #15
RoSk0As correctly pointed out by the colleague ( thanks Phil ) TransferException doesn't have the getRequest() method.
Comment #18
DamienMcKennaOne problem is that Guzzle only returns the first 120 characters of the response if there's an exception in the request; RequestException::create() calls get_message_body_summary() (without the second argument to set the message length so it defaults to 120 characters), which calls Message::bodySummary(), which truncates the string to the default of 120 characters. Argh.
Comment #19
DamienMcKennaI think in order to get the full string from guzzle you'd need to extend GuzzleHttp\Exception\RequestException, override the getResponseBodySummary() method and pass in a larger number to get_message_body_summary(), and change core to use the new exception handler instead of the Guzzle one.
Comment #20
ranjith_kumar_k_u CreditAttribution: ranjith_kumar_k_u at Zyxware Technologies commentedRe-rolled for 9.4.
Comment #24
jweowu CreditAttribution: jweowu at Catalyst IT commentedn.b. #20 no longer applies as of 9.4.8.
Comment #25
jweowu CreditAttribution: jweowu at Catalyst IT commentedRe-rolled for 9.4.x (accounting for #3310510: Harden error logging of OEmbed thumbnail fetching logic (YouTube errors contain special characters) released in 9.4.8).
Comment #26
Martijn de WitI think we need a patch for 10.1.x-dev. That's the new patch version. see #23
Comment #27
jweowu CreditAttribution: jweowu at Catalyst IT commentedThe same patch has passed testing for 10.1.x, so I guess we don't need a re-roll for that after all.
I'm still trying to get the testbot to show green for some test cases, but I think those issues are unrelated to the patch.
Comment #28
Kristen PolCan we also get another error message fixed with this patch?
With this video https://www.youtube.com/watch?v=HmZKgaHa3Fg, I was getting this error:
which doesn't have the exception message so isn't very helpful.
This should be changed from:
to something like:
With the change, the error for this video is:
Comment #29
pooja saraah CreditAttribution: pooja saraah at Srijan | A Material+ Company for Drupal India Association commentedAddressed the comment on #28
Attached patch against Drupal 10.1.x
Comment #30
Prem Suthar CreditAttribution: Prem Suthar at Srijan | A Material+ Company for Drupal India Association commentedTry To Fix the #29 Patch Faild To Apply.
Comment #31
AnybodyGreat point @Kristen Pol in #28.
I just came here to write the same. The current message "Could not retrieve the oEmbed resource" is very unclear and you have no good way to identify which oEmbed resource / entity causes the issue!
Just wrote a blog post about that: https://julian.pustkuchen.com/en/understanding-drupal-media-error-messag...
Comment #32
AnybodyJust found this similar issue: #3202896: Don't display OEmbed error to anonymous visitors when resource stops being available
Guess both should be solved together.
Comment #33
xurizaemon#29 didn't apply, and #30 failed tests, so here's #25 reroll + #28 for #drupalsouth code sprint
Comment #35
xurizaemonAnd an update for the change in error message.
Comment #36
xurizaemonCorrecting interdiff.
Comment #37
xurizaemonLast try for today.
Comment #39
xurizaemonOk, this works, but on reflection: by changing the error message the user sees, I'm now concerned that we might be straying into messing with localisation.
The text change here is from "Could not retrieve the oEmbed resource." to "Could not retrieve the oEmbed resource: " followed by the supplied exception message.
I don't see instructions on considerations for changing UI text in https://www.drupal.org/docs/develop/user-interface-standards/interface-text - I recall we have responsibilities here though.
On mobile now and can't load localize. Drupal.org but appreciate input on how to best make that improvement.
Comment #40
smustgrave CreditAttribution: smustgrave at Mobomo commentedCan the issue summary be updated please. started with the template.
Also will need additional test coverage.
Comment #41
xurizaemonUpdating IS from core template.
I am open to NOT changing user facing messages if that permits us to land the original proposed change (logging but not messages) more easily. I'll add an alternative patch without the message and related test change so we have that option.
Given #3202896: Don't display OEmbed error to anonymous visitors when resource stops being available it may be better to leave user facing changes to that issue.
@smustgrave if we go that way, do you feel additional tests are required?
Comment #42
smustgrave CreditAttribution: smustgrave at Mobomo commentedWould need a test for the logs.
The current test update is just checking for a ":" being added.
Comment #44
AnybodyRe #41 I agree the user facing message might stay as-is, simply log the details. I think that's what you'd expect and is most safe.
Really annoying to not see details in the log and only this not very helpful message. Perhaps we should gain the priority here.
Comment #45
thomas.frobieterPatch #39 applies on 9.5.x but results in the following error when creating a new external Video Media Entity:
Edit: The reason is that both kind of Exceptions are handled through the same function:
but only Drupal\media\OEmbed\ResourceException has a ->getUrl() so that needs to be split.
The second exception here is a GuzzleHttp\Exception\ClientException so the call fails!
Comment #46
AnybodyNeeds work as of #45. One way might be to implement __toString() differently in the two exception classes and just call that instead of ->getUrl() and others.
Another alternative would be to have two different handleException() function. Which way should we go?
Comment #47
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedThere seem to be further Exceptions like "ClientException", which do not have the url part implemented. I guess data would be enough for those exceptions, and we only add the url for when it is an ResourceException?
EDIT: Damn "ClientException" doesn't even have the "getData()" function implemented...
Comment #48
AnybodyRe #47: Yes!
Comment #49
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedI just wondered why "ClientException" is even handled by our "handleException" method, since we only catch "ResourceException" and "ProviderException".
The problem is line 153 -> 154 in "/var/www/html/web/core/modules/media/src/Plugin/Validation/Constraint/OEmbedResourceConstraintValidator.php":
This while loop will rerun our handleException method, with the previous Throwable, and since in my case this is a "ClientException" it will fail on $e->getData().
Is this intended behavior? Should we also handle other exceptions then "ResourceException" and "ProviderException", even if we do not explicitly catch them in code?? Seems pretty dirty to me.
Comment #50
AnybodyYes, that's indeed intended, as the exceptions are wrapping each other. I personally don't really like this do ... while thing, but that's not our decision, I guess and existed before this patch.
Anyway special methods may only be called, if they are implemented. As written above, another option would be to override __toString in the Exception to provide further information, instead of using if-clauses, but there are many pro's and con's. Someone has to decide here, which way to go or simply take one way...
Comment #52
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedInterdiff between "2972846-39-media-oembed-error.patch" and "2972846-improve-oembed-exception" can be seen here: https://git.drupalcode.org/project/drupal/-/merge_requests/4059/diffs?co....
A minor problem still remains. As we are logging inside a while loop, there is the possibility of logging multiple errors with practically the same output:
First log message:
Second log message:
I also tried adjusting / adding tests, but the currently implemented oembed tests are super "stuffed" and overwhelming. Maybe someone else with a bit more inside knowledge could adjust them accordingly. I would've simply enabled the "media" module and tested on the "remote_video" media type, but that seems way too much unnecessary overhead for such a simple test.
Comment #53
smustgrave CreditAttribution: smustgrave at Mobomo commentedMoving to NW for the additional test coverage.
Since this is testing log messages there may be some trait that could do that? Worth posting in #testing for any suggestions.
Comment #54
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedAlright, I added an error logging test taking inspiration from
dblog/tests/src/Functional/DbLogTest.php, testLogEventPage()
, on how to receive the logged watchdog event id. The only problem left is, that the test will fail.For some reason the latest watchdog log, is NOT our logged oembed error event and the event is NOT logged at all, when checking the watchdog overview!
I am unsure, why that is. I already tried enabling the media and media_library modules, and trying some other workarounds (like pressing the "Add" button multiple times and checking on the dblog overview, for any error event to get logged), but with no avail.
I'll ask in the Slack testing channel. Maybe someone there might have an idea.
Comment #55
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedThis is the test output of the "Recent log messages" page with and without media and media_library enabled, AFTER the "ResourceException" gets thrown and displayed on the page:
Comment #56
smustgrave CreditAttribution: smustgrave at Mobomo commentedSeems test failure is legit to the issue.