Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #45 from GoogleChrome/friendlier-errors
Browse files Browse the repository at this point in the history
Friendlier error messages for two types of bad parameters.
  • Loading branch information
jeffposnick committed Nov 2, 2015
2 parents d6436bf + 948ff78 commit 4803e63
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/sw-precache.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,29 @@ function generate(params, callback) {
});

Object.keys(params.dynamicUrlToDependencies).forEach(function(dynamicUrl) {
if (!Array.isArray(params.dynamicUrlToDependencies[dynamicUrl])) {
throw Error(util.format(
'The value for the dynamicUrlToDependencies.%s option must be an Array.', dynamicUrl));
}

var filesAndSizesAndHashes = params.dynamicUrlToDependencies[dynamicUrl]
.sort()
.map(getFileAndSizeAndHashForFile);
.map(function(file) {
try {
return getFileAndSizeAndHashForFile(file);
} catch (e) {
// Provide some additional information about the failure if the file is missing.
if (e.code === 'ENOENT') {
params.logger(util.format(
'%s was listed as a dependency for dynamic URL %s, but the file does not exist. ' +
'Either remove the entry as a dependency, or correct the path to the file.',
file, dynamicUrl
));
}
// Re-throw the exception unconditionally, since this should be treated as fatal.
throw e;
}
});
var concatenatedHashes = '';

filesAndSizesAndHashes.forEach(function(fileAndSizeAndHash) {
Expand Down

0 comments on commit 4803e63

Please sign in to comment.