0

Occasionally I am encountering an error along these lines:

The website encountered an unexpected error. Please try again later.InvalidArgumentException: The URI 'XYZ' is invalid. You must use a valid URI scheme. in Drupal\Core\Url::fromUri() (line 290 of core/lib/Drupal/Core/Url.php).

We are migrating data frequently and one thing that can happen is link field URIs can come in like that. The core LinkFormatter class does not seem to handle exceptions, although there is this issue:

https://www.drupal.org/project/drupal/issues/2745179

If this patch does not apply/work, what other resolution is there? Should I point the LinkFormatter class definition to a custom class that catches exceptions?

1
  • I'd add a check to ensure the URLs are valid before importing them. But if you want a proper answer, you'll need to provide a lot more detail, as there isn't enough there to give any kind of meaningful answer.
    – Jaypan
    Sep 29, 2021 at 18:08

1 Answer 1

1

Turns out that the patch for this core LinkFormatter class (#50) works against Drupal 9.2.6 currently.

There are a few ways this data can get into the application outside of user-entry in Drupal forms where we cannot always validate that a link URI is good or whats intended from external API sources. This patch catches exceptions and allows the site to function normally for the public.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.