Skip to content

Commit 1eebc9a

Browse files
committed
Normalize structure parsing error
1 parent 0a94c80 commit 1eebc9a

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

lib/book.js

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,13 @@ Book.prototype.parseReadme = function() {
377377
that.log.debug.ln("readme located at", that.readmeFile);
378378
return that.template.renderFile(that.readmeFile)
379379
.then(function(content) {
380-
return readme.parser.readme(content);
380+
return readme.parser.readme(content)
381+
.fail(function(err) {
382+
throw that.normError(err, {
383+
name: err.name || "Readme Parse Error",
384+
fileName: that.readmeFile
385+
});
386+
});
381387
});
382388
})
383389
.then(function(readme) {
@@ -404,7 +410,13 @@ Book.prototype.parseLangs = function() {
404410
that.log.debug.ln("languages index located at", that.langsFile);
405411
return that.template.renderFile(that.langsFile)
406412
.then(function(content) {
407-
return langs.parser.langs(content);
413+
return langs.parser.langs(content)
414+
.fail(function(err) {
415+
throw that.normError(err, {
416+
name: err.name || "Langs Parse Error",
417+
fileName: that.langsFile
418+
});
419+
});
408420
});
409421
})
410422
.then(function(langs) {
@@ -435,6 +447,12 @@ Book.prototype.parseSummary = function() {
435447
entryPoint: that.readmeFile,
436448
entryPointTitle: that.i18n('SUMMARY_INTRODUCTION'),
437449
files: that.files
450+
})
451+
.fail(function(err) {
452+
throw that.normError(err, {
453+
name: err.name || "Summary Parse Error",
454+
fileName: that.summaryFile
455+
});
438456
});
439457
});
440458
})
@@ -463,7 +481,13 @@ Book.prototype.parseGlossary = function() {
463481
that.log.debug.ln("glossary located at", that.glossaryFile);
464482
return that.template.renderFile(that.glossaryFile)
465483
.then(function(content) {
466-
return glossary.parser.glossary(content);
484+
return glossary.parser.glossary(content)
485+
.fail(function(err) {
486+
throw that.normError(err, {
487+
name: err.name || "Glossary Parse Error",
488+
fileName: that.glossaryFile
489+
});
490+
});
467491
});
468492
})
469493
.then(function(glossary) {
@@ -742,15 +766,12 @@ Book.prototype.i18n = function(phrase) {
742766
};
743767

744768
// Normalize error
745-
Book.prototype.normError = function(err, opts) {
746-
opts = _.defaults(opts || {}, {
747-
748-
});
749-
769+
Book.prototype.normError = function(err, opts, defs) {
750770
if (_.isString(err)) err = new Error(err);
751771

752772
// Extend err
753-
_.extend(err, opts);
773+
_.extend(err, opts || {});
774+
_.defaults(err, defs || {});
754775

755776
err.lineNumber = err.lineNumber || err.lineno;
756777
err.columnNumber = err.columnNumber || err.colno;
@@ -762,7 +783,7 @@ Book.prototype.normError = function(err, opts) {
762783
if (this.lineNumber) attributes.push("Line "+this.lineNumber);
763784
if (this.columnNumber) attributes.push("Column "+this.columnNumber);
764785
return (this.name || "Error")+": "+this.message+((attributes.length > 0)? " ("+attributes.join(", ")+")" : "")
765-
}
786+
};
766787

767788
return err;
768789
};

0 commit comments

Comments
 (0)