Skip to content

Commit

Permalink
Fix: Uncaught exceptions cause a silent exit (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
amad-person authored and yamgent committed Feb 25, 2019
1 parent 14b8a5c commit a91b2de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/lib/markbind/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ Parser.prototype._preprocess = function (node, context, config) {

// Render inner file content
fileContent = nunjucks.renderString(fileContent,
{ ...pageVariables, ...includeVariables, ...userDefinedVariables });
{ ...pageVariables, ...includeVariables, ...userDefinedVariables },
{ path: actualFilePath });

// Delete variable attributes in include
Object.keys(element.attribs).forEach((attribute) => {
Expand Down Expand Up @@ -504,7 +505,9 @@ Parser.prototype.includeFile = function (file, config) {
const { parent, relative } = calculateNewBaseUrls(file, config.rootPath, config.baseUrlMap);
const userDefinedVariables = config.userDefinedVariablesMap[path.resolve(parent, relative)];
const pageVariables = extractPageVariables(path.basename(file), data, userDefinedVariables, {});
const fileContent = nunjucks.renderString(data, { ...pageVariables, ...userDefinedVariables });
const fileContent = nunjucks.renderString(data,
{ ...pageVariables, ...userDefinedVariables },
{ path: actualFilePath });
const fileExt = utils.getExt(file);
if (utils.isMarkdownFileExt(fileExt)) {
context.source = 'md';
Expand Down Expand Up @@ -658,7 +661,7 @@ Parser.prototype._rebaseReference = function (node, foundBase) {
// and let the hostBaseUrl value be injected later.
hostBaseUrl: '{{hostBaseUrl}}',
baseUrl: newBaseUrl,
});
}, { path: filePath });
element.children = cheerio.parseHTML(rendered, true);
cheerio.prototype.options.xmlMode = true;
}
Expand Down Expand Up @@ -694,7 +697,7 @@ Parser.prototype._rebaseReferenceForStaticIncludes = function (pageData, element

const newBase = fileBase.relative;
const newBaseUrl = `{{hostBaseUrl}}/${newBase}`;
return nunjucks.renderString(pageData, { baseUrl: newBaseUrl });
return nunjucks.renderString(pageData, { baseUrl: newBaseUrl }, { path: filePath });
};

module.exports = Parser;
10 changes: 7 additions & 3 deletions src/util/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ const DailyRotateFile = require('winston-daily-rotate-file');
winston.configure({
exitOnError: false,
transports: [
new (winston.transports.Console)({
colorize: true,
handleExceptions: true,
humanReadableUnhandledException: true,
level: 'info',
showLevel: true,
}),
new DailyRotateFile({
datePattern: 'YYYY-MM-DD',
dirname: '_markbind/logs',
Expand All @@ -23,15 +30,12 @@ winston.configure({

module.exports = {
error: (text) => {
console.log(chalk.red(`error: ${text}`));
winston.error(text);
},
warn: (text) => {
console.log(chalk.yellow(`warning: ${text}`));
winston.warn(text);
},
info: (text) => {
console.log(chalk.cyan('info: ') + text);
winston.info(text);
},
verbose: (text) => {
Expand Down

0 comments on commit a91b2de

Please sign in to comment.