diff options
author | Johan Preynat <johan.preynat@gmail.com> | 2016-10-01 22:48:47 +0200 |
---|---|---|
committer | Johan Preynat <johan.preynat@gmail.com> | 2016-10-01 22:48:47 +0200 |
commit | 32556e672431e9766388747285d69e65130013c0 (patch) | |
tree | f6a2fa1656ca4c31c47722f3530c0b86b14b5efe | |
parent | 8753897edc7119065d210c6cef8b5a0a555d322b (diff) | |
download | gitbook-32556e672431e9766388747285d69e65130013c0.zip gitbook-32556e672431e9766388747285d69e65130013c0.tar.gz gitbook-32556e672431e9766388747285d69e65130013c0.tar.bz2 |
Add fix for handling parsing page errors
-rw-r--r-- | packages/gitbook/src/parse/parsePageFromString.js | 1 | ||||
-rw-r--r-- | packages/gitbook/src/parse/parsePagesList.js | 31 |
2 files changed, 26 insertions, 6 deletions
diff --git a/packages/gitbook/src/parse/parsePageFromString.js b/packages/gitbook/src/parse/parsePageFromString.js index 2e4a598..c121e2c 100644 --- a/packages/gitbook/src/parse/parsePageFromString.js +++ b/packages/gitbook/src/parse/parsePageFromString.js @@ -9,6 +9,7 @@ const direction = require('direction'); * @return {Page} */ function parsePageFromString(page, content) { + // Parse page YAML const parsed = fm(content); return page.merge({ diff --git a/packages/gitbook/src/parse/parsePagesList.js b/packages/gitbook/src/parse/parsePagesList.js index ddac20e..2383dbf 100644 --- a/packages/gitbook/src/parse/parsePagesList.js +++ b/packages/gitbook/src/parse/parsePagesList.js @@ -11,15 +11,26 @@ const parsePage = require('./parsePage'); @param {Book} book @param {String} filePath - @return {Page} + @return {Page?} */ function parseFilePage(book, filePath) { const fs = book.getContentFS(); return fs.statFile(filePath) - .then(function(file) { - const page = Page.createForFile(file); - return parsePage(book, page); + .then( + function(file) { + const page = Page.createForFile(file); + return parsePage(book, page); + }, + function(err) { + // file doesn't exist + return null; + } + ) + .fail(function(err) { + const 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); }); }) |