Problem/Motivation

While working on #3004718: Better MigrateException message in the format_date process plugin I found that the (equally bad) UnexpectedValueException message was not being tested.

Proposed resolution

Add a test for throwing an UnexpectedValueException.

Remaining tasks

Write patch.

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jo Fitzgerald created an issue. See original summary.

jofitz’s picture

Assigned: jofitz » Unassigned
Status: Active » Needs review
FileSize
2.15 KB

Added test (and improved exception message in line with #3004718: Better MigrateException message in the format_date process plugin.

quietone’s picture

Status: Needs review » Needs work

@Jo Fitzgerald, good catch.

Let's add the destination property to this and then get this in. There is a suggestion in #2959444-Comment #10 to add a method on ProcessPluginBase to help with the error messages. But in the meantime just adding the destination property is helpful.

quietone’s picture

Status: Needs work » Reviewed & tested by the community

Ah, it was right in front of me, the destination property is there!

quietone’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/migrate/src/Plugin/migrate/process/FormatDate.php
@@ -136,7 +136,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
+      throw new MigrateException(sprintf('Format date plugin could not transform %s value "%s" using the format "%s". Error: %s', $destination_property, $value, $fromFormat, $e->getMessage()), $e->getCode(), $e);

Nothing like a toddler to make me lose what I was trying to do here. I think the message needs tweaking. Saying that the plugin could not transform the destination property isn't quite right since the source value is transformed not the destination. Looking at the process plugins in the migrate for ideas there is only StaicMap that uses the destination_property in the error message.
throw new MigrateSkipRowException(sprintf("No static mapping found for '%s' and no default value provided for destination '%s'.", Variable::export($value), $destination_property));

Using that as a guide how about 'Format date plugin could not transform value "%s" using the format "%s" for destination '%s'. Error: %s' ?
What do you think?

jofitz’s picture

Status: Needs work » Needs review
FileSize
2.1 KB
2.17 KB

Corrected the exception message.

quietone’s picture

Status: Needs review » Reviewed & tested by the community

@Jo Fitzgerald, excellent, thanks!

This adds a test for the exception message from FormatDate, which Jo Fitzgerald spotted and fixed, and the message includes more context which is always useful. There are plans to add even more context to the process plugin exception messages but that is still in the early stages and should not hold this up.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 148b87f and pushed to 8.7.x. Thanks!

  • catch committed 148b87f on 8.7.x
    Issue #3011069 by Jo Fitzgerald, quietone: Incomplete testing for...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.