Today, while trying to set up my first file migration, I had this error:

New object was not saved, no error provided.

... which later I found out there was a little more information by clicking through to see the "messages" for my migration:

The specified file /sites/default/files/mysourcedir/some_file.jpg could not be copied to public://newsubdir/some_file.jpg

It took me quite a while to get to the bottom of the problem, which I did by adding a slightly different error-handler, which provided more information. Here is how it looks now:

The specified file /sites/default/files/mysourcedir/some_file.jpg could not be copied to public://newsubdir/some_file.jpg
"copy(/sites/default/files/mysourcedir/some_file.jpg): failed to open stream: No such file or directory File /sites/all/modules/contrib/migrate/plugins/destinations/file.inc, line 358"

"No such file or directory" was much more helpful than "could not be copied".

(Incidentally, my problem was that I had specified my source_dir as "/sites/default/files". The way the migrate module magically gets everything else out of the source drupal site (this is a drupal-to-drupal migration) led me to think that it would already know my the drupal root of my source site (much as drush does). )

Patch is attached for my minor improvement.

Comments

dan3h’s picture

Issue summary: View changes
StatusFileSize
new1.14 KB

Here is a patch for the improvement.

dan3h’s picture

StatusFileSize
new1.14 KB

Oops... patch had a typo -- an extra 't' in one of the '%migrate_excepttion' tokens.

New and improved version attached.

13rac1’s picture

Status: Active » Needs review

Running tests.

Status: Needs review » Needs work

The last submitted patch, 2: migrate-clearer-errors-2141687-2.patch, failed testing.

The last submitted patch, 1: migrate-clearer-errors-2141687.patch, failed testing.

seemlesstaylor’s picture

I'm new to Drupal and it's community, so I don't have the knowledge or the time right now to write a test and make this a patch, but this code was very useful to me in 'making error messages include more information', at least for file migrations. I simply added a try/catch to the copyFile function in modules\migrate\plugins\destinations\file.inc and added the exception message to the migration message. My new function reads as follows:

protected function copyFile($destination) {
	$this->sourcePath = self::urlencode($this->sourcePath);
	try {
		if (copy($this->sourcePath, $destination)) {
			return TRUE;
		}
	} catch (Exception $e) {
		$migration = Migration::currentMigration();
		$migration->saveMessage(t('The specified file %file could not be copied to ' .
			'%destination. Error: ' . $e->getMessage(),
			array('%file' => $this->sourcePath, '%destination' => $destination)));
		return FALSE;
	}
}

As much time as various un-informative errors have cost our team, I thought it would be more helpful to the community to put this out there than to wait until I could submit it as a proper patch.

mikeryan’s picture

Category: Bug report » Feature request

@dan3h: Could you submit a proper Drupal patch? tl;dr - do a git diff in the module directory.

Thanks.

othermachines’s picture

Title: Make error messages include more information » Make error messages include more information when migrating files
Priority: Minor » Normal
Status: Needs work » Needs review
StatusFileSize
new1.47 KB

I badly needed this to debug a WordPress import. I created a patch from @dan3h's code, but with typos and formatting fixed.

Error message before:

The specified file http://www.domain.se/wp-content/uploads/1234.png could not be copied to public://wp-content/uploads/1234.png.

Error message after:

The specified file http://www.domain.se/wp-content/uploads/1234.png could not be copied to public://wp-content/uploads/1234.png: "copy(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 File C:\wamp\www\abc\sites\all\modules\contrib\migrate\plugins\destinations\file.inc, line 410"

dan3h’s picture

@othermachines: Thanks for making my patch into a proper drupal patch. Sorry, @mikeryan, for totally missing your message from a year ago!

mikeryan’s picture

Issue tags: +Migrate 2.8

  • mikeryan committed 2964239 on 7.x-2.x authored by dan3h
    Issue #2141687 by dan3h,othermachines: Provide detailed message on file...
mikeryan’s picture

Status: Needs review » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

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