diff options
author | Johan Preynat <johan.preynat@gmail.com> | 2016-10-01 21:47:25 +0200 |
---|---|---|
committer | Johan Preynat <johan.preynat@gmail.com> | 2016-10-01 21:47:25 +0200 |
commit | cb3d6a7f0192f6b67e8cbf22dcf4576ff8c85a70 (patch) | |
tree | 8543ef10b2c0cb5875a366876b9fac9c9b6314dc /lib/parse/parsePagesList.js | |
parent | c978f0ab217294bbf0899e36b918b45c084d2d0c (diff) | |
download | gitbook-cb3d6a7f0192f6b67e8cbf22dcf4576ff8c85a70.zip gitbook-cb3d6a7f0192f6b67e8cbf22dcf4576ff8c85a70.tar.gz gitbook-cb3d6a7f0192f6b67e8cbf22dcf4576ff8c85a70.tar.bz2 |
Correctly handle page parsing errors
Diffstat (limited to 'lib/parse/parsePagesList.js')
-rw-r--r-- | lib/parse/parsePagesList.js | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/lib/parse/parsePagesList.js b/lib/parse/parsePagesList.js index 1cf42f5..fa15a9d 100644 --- a/lib/parse/parsePagesList.js +++ b/lib/parse/parsePagesList.js @@ -11,15 +11,26 @@ var parsePage = require('./parsePage'); @param {Book} book @param {String} filePath - @return {Page} + @return {Page?} */ function parseFilePage(book, filePath) { var fs = book.getContentFS(); return fs.statFile(filePath) - .then(function(file) { - var page = Page.createForFile(file); - return parsePage(book, page); + .then( + function(file) { + var page = Page.createForFile(file); + return parsePage(book, page); + }, + function(err) { + // file doesn't exist + return null; + } + ) + .fail(function(err) { + var logger = book.getLogger(); + logger.error.ln('error while parsing page "' + filePath + '":'); + throw err; }); } @@ -48,9 +59,12 @@ function parsePagesList(book) { return parseFilePage(book, filepath) .then(function(page) { - map = map.set(filepath, page); - }, function() { // file doesn't exist + if (!page) { + return; + } + + map = map.set(filepath, page); }); }) ) @@ -65,6 +79,11 @@ function parsePagesList(book) { return parseFilePage(book, file.getPath()) .then(function(page) { + // file doesn't exist + if (!page) { + return; + } + map = map.set(file.getPath(), page); }); }) |