[D11] RouteNotFoundException thrown when viewing imported product variations

Created on 15 August 2024, 8 months ago
Updated 6 September 2024, 8 months ago

Problem/Motivation

Using Drupal 11, Commerce Core 3.x and Commerce Feeds, when after importing product variations, you go to the 'Items' page, you'll get the following error:

Symfony\Component\Routing\Exception\RouteNotFoundException: in Drupal\commerce_product\Entity\ProductVariation->toUrl() (line 118 of modules/contrib/commerce/modules/product/src/Entity/ProductVariation.php).

Steps to reproduce

On Drupal 11.0.1

  1. Install Commerce Feeds, Commerce Core 3.x and all its dependencies.
  2. Create a feed type, use the Product variation processor.
  3. Map to sku, title and price.
  4. Create a feed and import.
  5. Go to the 'Items' page, for example /feed/1/list.

Proposed resolution

Catch and ignore exceptions of \Symfony\Component\Routing\Exception\RouteNotFoundException.

\Drupal\commerce_product\Entity\ProductVariation::toUrl() tells us the following:

// RouteNotFoundException tells EntityBase::uriRelationships()
// to skip this product variation's link relationships.

\Drupal\Core\Entity\EntityBase::uriRelationships() reveals a \Symfony\Component\Routing\Exception\MissingMandatoryParametersException is another possible exception that could be thrown during the process, so catch and ignore that one as well.

Finally, \Drupal\Core\Entity\EntityBase::toUrl() could throw \Drupal\Core\Entity\EntityMalformedException, however that would I see as an error that should not be ignored. Nevertheless, catch it and display an error message in this case. While we are at it, just catch any exception and log it to prevent the page from crashing in the future.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇳🇱Netherlands megachriz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024