Uncaught ProviderException if neither remote provider database nor locally stored version is available

Created on 28 August 2024, 4 months ago

Problem/Motivation

Drupal uses an http request to oembed.com's providers.json to pull oEmbed provider information. On occasions when the request fails, the http client throws a Guzzle Exception. In #3186184: Make oEmbed provider repository more fault-tolerant if provider database is unavailable β†’ , handling failed requests was made more fault-tolerant by storing a local copy of the provider data to Drupal's keyvalue store. However, in the case that there is no existing stored copy and the request fails, a ProviderException is thrown and is uncaught by the OEmbedFormatter, which can lead to WSOD. From comment 20 β†’ :

I think we should still throw the exception, since that is happening in the plumbing of the oEmbed system, and indeed, an inability to fetch the provider data is a serious error condition.

However, I agree that we don't necessarily want that to cause a WSOD. We should make it fail more gracefully. My recommendation is to add that defensiveness to the consumers of the oEmbed system -- namely, the oEmbed field formatter as the main culprit. It should probably catch and handle every potential oEmbed exception, including this one, and produce some useful logging/prevent a WSOD.

This is a follow up to add the error handling to OEmbedFormatter and other places where UrlResolver::getResourceUrl() is called.

Steps to reproduce

Make a corrupt JSON file (i.e., bad syntax) where your web server can serve it, and point the media.settings:oembed_providers_url config value at its URL. Then clear caches, delete the oembed_providers in the media collection of keyvalue storage, and delete the and look at any oEmbed-based media item, or page that contains oEmbed media (e.g., embedded YouTube videos).

Proposed resolution

Catch Drupal\media\OEmbed\ProviderException and log in:

  • Drupal\media\Plugin\Field\FieldFormatter\OEmbedFormatter::viewElements()
  • Drupal\media\Controller\OEmbedIframeController::render()
  • Drupal\media\Plugin\Validation\Constraint\OEmbedResourceConstraintValidator::validate()
  • Drupal\media\Form\OEmbedForm::validateUrl()

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
MediaΒ  β†’

Last updated 1 day ago

Created by

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024