From 4ea2357e113b852e343720f1bfb2bbdc26bbbace Mon Sep 17 00:00:00 2001 From: Jeff Posnick Date: Fri, 30 Oct 2015 13:28:59 -0400 Subject: [PATCH 1/2] Friendlier error messages for two types of bad parameters. --- lib/sw-precache.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/sw-precache.js b/lib/sw-precache.js index 83f84e0..28a6890 100644 --- a/lib/sw-precache.js +++ b/lib/sw-precache.js @@ -116,9 +116,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) { From 948ff78e3498dbcfcc427a4d59889d4c9fc2dbe9 Mon Sep 17 00:00:00 2001 From: Jeff Posnick Date: Fri, 30 Oct 2015 13:36:48 -0400 Subject: [PATCH 2/2] Clean up linting error --- lib/sw-precache.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sw-precache.js b/lib/sw-precache.js index 28a6890..69bd0c2 100644 --- a/lib/sw-precache.js +++ b/lib/sw-precache.js @@ -126,7 +126,7 @@ function generate(params, callback) { .map(function(file) { try { return getFileAndSizeAndHashForFile(file); - } catch(e) { + } catch (e) { // Provide some additional information about the failure if the file is missing. if (e.code === 'ENOENT') { params.logger(util.format(