Problem/Motivation
As per https://www.drupal.org/project/drupal/issues/3156730#comment-13877360
throw new MigrateException(sprintf('A(n) %s was thrown while attempting to stub.', gettype($exception)), $exception->getCode(), $exception);
...This is resulting in hard-to-debug messages such as:
A(n) object was thrown while attempting to stub.
It'd be better to include the exception class + message, like so:throw new MigrateException(sprintf('A(n) %s was thrown while attempting to stub, with the following message: %s.', get_class($exception), $exception->getMessage()), $exception->getCode(), $exception);
Steps to reproduce
Run any migration that throws an exception.. View message in migration messages table for that migration.
Proposed resolution
Replace with something similar to the following code snippet that includes the exception message in the message. (not this, it needs work):
throw new MigrateException(sprintf('A(n) %s was thrown while attempting to stub, with the following message: %s.', get_class($exception), $exception->getMessage()), $exception->getCode(), $exception);
Remaining tasks
Verify green/red with full/tests-only patches
Review patch
Commit.
User interface changes
NA
API changes
NA
Data model changes
NA
Release notes snippet
NA
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 3202665-18.patch | 2.14 KB | danflanagan8 |
| #8 | interdiff_5-8.txt | 844 bytes | Ratan Priya |
| #8 | 3202665-8.patch | 810 bytes | Ratan Priya |
| #5 | 3202665-migrate-exception-message-5.patch | 826 bytes | rupertj |
Comments
Comment #5
rupertj commentedI ran into this issue. The current message really isn't helpful. The patch attached changes this:
To this:
Comment #6
longwaveThis could be shortened to just
'%s was thrown while attempting to stub: %s'Is there a simple way of writing a test case that covers this?
Comment #7
smustgrave commentedMoving to NW for the comment #6. I don't know about a test case. Could we test the error message returned?
Comment #8
Ratan Priya commented@longwave,
Made changes as per comment #6, but still, need work for the test case.
Comment #9
danflanagan8Updating issue metadata to reflect the need for tests.
Comment #10
danflanagan8I actually want to try to write these tests. Assigning to me.
Comment #11
smustgrave commentedAdded a test case and updated issue summary
Comment #12
smustgrave commentedOops sorry @danflanagan8 I didn't see that comment before starting to work on this.
Comment #13
danflanagan8Here's a test case to address this. I'm uploading a patch that runs just the test class that's modified in an attempt to be stingy with resources.There is not much coverage for exception handling by the MigrationLookup process plugin. We could add a lot more coverage but this might not be the time or place to do it.
nm, I got scooped! I'm unassigning from myself and I guess I'll review instead. My test looked almost exactly like the one added in #11, but I did a couple things differently that I like.
First I used a new test method rather than adding to an existing one. These are unit tests, so we don't need to worry about saving processing time. I prefer the clarity that comes from a separate test. A separate test also allows for easy use of a dataProvider if we were to decide to test the other exception handling related to stubbing.
Second, I used an EntityStorageException instead of just an \Exception. I prefer EntityStorageException because it makes it clearer that the first word in the message is being populated based on the exception class. One could imagine that the word "Exception" is hardcoded at the beginning of the message.
I guess a third thing I did was to update drupalci.yml so that we save resources while running the test-only patch here. That's a really nice trick that I like share:
I think at the end of the day, though, the test in #11 is good enough. I'll RTBC if things come back green!
Comment #14
danflanagan8Status got messed up during a cross post.
Comment #16
danflanagan8Setting back to NR because the tests are still running on #11.
Please ignore the patch in #13 which I did not mean to upload.
Comment #18
danflanagan8The patch in #11 looks great. Due to the cross posting (#13) though, I think I need to re-upload the patch from #11 here so that it's clear what patch I'm RTBC-ing. I downloaded the patch from #11, changed the name, and I am re-uploading here.
Also, for some reason (the cross post?) @smustgrave is not checked in the credits box. Let's make sure he gets his due! Thanks all!
Comment #20
danflanagan8Unrelated ckeditor5 fail. Resetting status to RTBC.
Comment #22
longwaveUnrelated Quick Edit fail this time, back to RTBC again.
Comment #24
longwaveAnother ckeditor5 fail.
Comment #25
alexpottCommitted and pushed 2e76fda4ff to 10.1.x and 599814852c to 10.0.x and 8671583c12 to 9.5.x and 6acd4fddc2 to 9.4.x. Thanks!
Backported this to 9.4.x as useful low risk bug fix.