From a91b2de54d8128fb1e296930af9c034c64519534 Mon Sep 17 00:00:00 2001 From: Aadyaa Maddi Date: Mon, 25 Feb 2019 10:20:23 +0800 Subject: [PATCH] Fix: Uncaught exceptions cause a silent exit (#721) --- src/lib/markbind/src/parser.js | 11 +++++++---- src/util/logger.js | 10 +++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lib/markbind/src/parser.js b/src/lib/markbind/src/parser.js index c55a64794c..5f93a42e4e 100644 --- a/src/lib/markbind/src/parser.js +++ b/src/lib/markbind/src/parser.js @@ -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) => { @@ -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'; @@ -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; } @@ -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; diff --git a/src/util/logger.js b/src/util/logger.js index ee12c4df17..dd8b151c79 100644 --- a/src/util/logger.js +++ b/src/util/logger.js @@ -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', @@ -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) => {