Problem/Motivation

In #2976098: MigrateExecutable should add details for the migration & destination property to exceptions that cause a row failure, the migration ID and destination property was added to migration failure messages.

For a process pipeline with several plugins, that can still leave some detective work finding the source of the problem.

It would be useful to add the process plugin ID.

Steps to reproduce

Trigger a MigrateException in a process plugin. For example, pass an array as the source value to explode.

Proposed resolution

Move the catch in import():

        catch (MigrateException $e) {
          $this->getIdMap()->saveIdMapping($row, [], $e->getStatus());
          $msg = sprintf("%s:%s: %s", $this->migration->getPluginId(), $destination_property_name, $e->getMessage());
          $this->saveMessage($msg, $e->getLevel());
          $save = FALSE;
        }

to processPipeline(), which has the plugin name.

This should then re-throw the exception with the process plugin details prefixed to the message.

Remaining tasks

Review and commit

User interface changes

The plugin id will be displayed on the error messages.

API changes

none

Data model changes

none

Release notes snippet

TBD

Issue fork drupal-3254347

Command icon 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

joachim created an issue. See original summary.

joachim’s picture

Status: Active » Needs review

Before:

> two_images_parallax:_field_parallax_background_image_media: NULL is not a string

In a complex pipeline with several plugins, it's not obvious which plugin has said 'NULL is not a string', and with plugins scattered between core, migrate_plus, and custom code, it's not easy to find the exception message.

After:

> two_images_parallax:_field_parallax_background_image_media:4:explode: NULL is not a string

The message now says it's the 4th plugin in the pipeline, which is 'explode' which produced the message.

danflanagan8’s picture

Status: Needs review » Needs work

I personally like this idea, and the implementation is really simple.

The failing tests are all directly related to the error message being updated here. Those assertions should be easy to update. Setting to NW to get those tests updated.

murilohp made their first commit to this issue’s fork.

murilohp’s picture

Status: Needs work » Needs review

Moving back to needs review! I hope the tests pass.

danflanagan8’s picture

Status: Needs review » Needs work
StatusFileSize
new98.96 KB
new43.93 KB

I took a look at this in my new favorite toy, Migrate Sandbox, and found something funny. The way that migrate adds a get plugin to the pipeline anytime source is specified can lead to some strange things. First and foremost, I expect the first process plugin to be index 0 but it gets called index 1.

And if I happen to declare source multiple times in a pipeline (which is rare but allowed), I get an index of 3 where I might be expecting a 1.

I'm going to set back to NW. I think subtracting 1 from the index would be good since my second screenshot is something of an edge case.

joachim’s picture

I did spot the way the plugins were 1-based rather than 0-based, but shrugged at it and figured it just made it easier to understand the output.

Thanks for figuring it out!

> I think subtracting 1 from the index would be good since my second screenshot is something of an edge case.

I think we can handle that though.

If instead of relying on the numeric index of the plugin array here:

    foreach ($plugins as $index => $plugin) {

we instead manually increment a counter in each iteration of the loop, unless the $plugin is a 'get'.

danflanagan8’s picture

we instead manually increment a counter in each iteration of the loop, unless the $plugin is a 'get'.

I think that would cover almost all real use cases. It's most unusual to explicitly add get to the yml.

joachim’s picture

> I think that would cover almost all real use cases. It's most unusual to explicitly add get to the yml.

Yes, probably, since specifying 'source' does an implicit 'get'.

I can see how we couldd handle that too -- add an internal configuration property to the 'get' plugin called something like 'implicitly_added', set it on all the 'get' plugins the system adds automatically, and pick that up in the count.

But I think that's overkill for a case that might never happen.

joachim’s picture

Status: Needs work » Needs review
danflanagan8’s picture

Status: Needs review » Needs work

we instead manually increment a counter in each iteration of the loop, unless the $plugin is a 'get'.

@joachim, it looks like you did the first part of this, but not the part after the comma: unless the $plugin is a 'get'. There's no check for get and the behavior appears to be unchanged.

joachim’s picture

Status: Needs work » Needs review

Oops! Fixed.

quietone’s picture

Status: Needs review » Needs work

Setting to NW for failing tests.

murilohp’s picture

Status: Needs work » Needs review

I updated the tests, it was basically what was mentioned on #4, hope the tests pass.

Thanks!

danflanagan8’s picture

Issue tags: +Needs subsystem maintainer review
StatusFileSize
new43.29 KB
new41.91 KB

This looks good to me. The indexes behave much more nicely now. Here's a screenshot (using Migrate Sandbox) to compare with the second one in #7:

The only problem with this implementation, which we have already noted in #10 is that if you happen to explicitly add get in your pipeline, then the index gets funny. Example:

I'm going to tag this for subsystem maintainer review because I think we need buy-in.

quietone’s picture

Adding the plugin ID to the error message is useful, no doubt about that. The index however is confusing, as the last example shows. I think the index should be removed to avoid that. I guess the worst case scenario is a long pipeline that uses, say, process plugin X multiple times and it is X that has the error. But how often is that? Still with the destination property name and the process plugin it will be much easier to debug. Or one could break up the pipeline and use pseudo properties. I am more concerned about migrations created with migrate-upgrade that have 'get' and are then modified so that some property pipelines have a visible 'get' and others do not.

edit: s/not/no in first sentence.

joachim’s picture

Status: Needs review » Needs work

Ok, let's take out the index from this MR.

I'll maybe make a follow-up for only counting visible 'gets' if I have time as per #10.

danflanagan8’s picture

Thanks for the review, @quietone!

murilohp’s picture

Status: Needs work » Needs review
Issue tags: +Needs issue summary update

Hey everyone, I removed the index to address #17, and also updated the tests. I'll move this to needs review but I think we need to update the issue summary right? Just because the index will not be displayed anymore.

Thanks!

quietone’s picture

Status: Needs review » Needs work

@murilohp, having an update to date issue summary helps well, everyone. And for committers anything we can do to make their task easier is a good thing in my book. Setting to NW for the issue summary update.

murilohp’s picture

Title: Add the process plugin ID and index to migration exception message » Add the process plugin ID to migration exception message
Issue summary: View changes
murilohp’s picture

Hey @quietone, thanks for the response, updated the issue summary, now we can move to needs review.

murilohp’s picture

Status: Needs work » Needs review
danflanagan8’s picture

Issue summary: View changes
Status: Needs review » Needs work
StatusFileSize
new96.06 KB

I think we're ALMOST done here. The index is no longer part of the message. Here's a screenshot from Migrate Sandbox.

There's still a reference to the index in a code comment though. I'll make a comment on the MR. Back to NW.

:(

murilohp’s picture

Status: Needs work » Needs review

Thanks for checking the comments @danflanagan8, now I think we're done.

danflanagan8’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, @murilohp. The tests are still running, but we know they'll pass. RTBC!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed f21dc6690ee to 10.0.x and 09c149e887d to 9.4.x. Thanks!

This looks helpful information. Nice work. I considered whether we need a CR here and I don;t think so - maybe a contrib test will break but the fix will be obvious and there should not be runtime code relying on exception message strings as an API.

  • alexpott committed f21dc66 on 10.0.x
    Issue #3254347 by murilohp, joachim, danflanagan8, quietone: Add the...

  • alexpott committed 09c149e on 9.4.x
    Issue #3254347 by murilohp, joachim, danflanagan8, quietone: Add the...

Status: Fixed » Closed (fixed)

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