From b39fc05dbb379773bf38fe3442424fe02d3272f1 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Mon, 20 Jun 2016 10:08:50 -0700 Subject: [PATCH] Print nicer error message if an asset directory is not found in any of the roots Summary: When an asset is included in a module, and the directory for that asset can't be found in any of the roots, it is hard to debug that, because the error message contains neither the name of the requested file, the sub directory it is located in, nor the roots that have been searched for it. It becomes more difficult, because that exception is created asynchronously. It contains the calling promise code. This diff makes the error message more useful by including the name of the file, the sub directory, and the roots. Reviewed By: bestander Differential Revision: D3456738 fbshipit-source-id: 60b81f04626ad386f7120247c5f5361c81c52968 --- packager/react-packager/src/AssetServer/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packager/react-packager/src/AssetServer/index.js b/packager/react-packager/src/AssetServer/index.js index c9b198a50..65f1edcfc 100644 --- a/packager/react-packager/src/AssetServer/index.js +++ b/packager/react-packager/src/AssetServer/index.js @@ -106,7 +106,8 @@ class AssetServer { return ( this._findRoot( this._roots, - path.dirname(assetPath) + path.dirname(assetPath), + assetPath, ) .then(dir => Promise.all([ dir, @@ -138,7 +139,7 @@ class AssetServer { ); } - _findRoot(roots, dir) { + _findRoot(roots, dir, debugInfoFile) { return Promise.all( roots.map(root => { const absRoot = path.resolve(root); @@ -162,7 +163,9 @@ class AssetServer { return stats[i].path; } } - throw new Error('Could not find any directories'); + + const rootsString = roots.map(s => `'${s}'`).join(', '); + throw new Error(`'${debugInfoFile}' could not be found, because '${dir}' is not a subdirectory of any of the roots (${rootsString})`); }); } @@ -194,7 +197,7 @@ class AssetServer { return map; } - + _getAssetDataFromName(platform, file) { return getAssetDataFromName(file, platform); }