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
This commit is contained in:
David Aurelio 2016-06-20 10:08:50 -07:00 committed by Facebook Github Bot 6
parent 930ef51646
commit 6345d17c79
1 changed files with 7 additions and 4 deletions

View File

@ -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);
}