From c411ee5106ab3e2cbd7019402c65f4d6d4549460 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 28 Mar 2013 14:06:50 +0000 Subject: [PATCH] Better error handling in boot.js --- core/boot.js | 63 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/core/boot.js b/core/boot.js index 1091e2b43..1ac7a4f62 100644 --- a/core/boot.js +++ b/core/boot.js @@ -62,6 +62,14 @@ $tw.utils.log = function(/* args */) { } }; +/* +Display an error and exit +*/ +$tw.utils.error = function(err) { + console.error(err); + process.exit(1); +}; + /* Check if an object has a property */ @@ -741,7 +749,7 @@ $tw.modules.execute = function(moduleName,moduleRoot) { exports = {}, moduleInfo = $tw.modules.titles[name]; if(!moduleInfo) { - throw new Error("Cannot find module named '" + moduleName + "' required by module '" + moduleRoot + "', resolved to " + name); + $tw.utils.error("Cannot find module named '" + moduleName + "' required by module '" + moduleRoot + "', resolved to " + name); } if(!moduleInfo.exports) { if(typeof moduleInfo.definition === "string") { // String @@ -890,7 +898,7 @@ $tw.modules.execute = function(moduleName,moduleRoot) { moduleInfo.exports = moduleInfo.definition; } } catch(e) { - throw "Error executing boot module " + name + ":\n" + e; + $tw.utils.error("Error executing boot module " + name + ":\n" + e); } } // Return the exports of the module @@ -1007,30 +1015,31 @@ $tw.loadWikiTiddlers = function(wikiPath,parentPaths) { var wikiInfoPath = path.resolve(wikiPath,$tw.config.wikiInfo), wikiInfo = {}, pluginFields; - // Load the wiki info file - if(fs.existsSync(wikiInfoPath)) { - wikiInfo = JSON.parse(fs.readFileSync(wikiInfoPath,"utf8")); - // Load any parent wikis - if(wikiInfo.includeWikis) { - parentPaths = parentPaths.slice(0); - parentPaths.push(wikiPath); - $tw.utils.each(wikiInfo.includeWikis,function(includedWikiPath) { - var resolvedIncludedWikiPath = path.resolve(wikiPath,includedWikiPath); - if(parentPaths.indexOf(resolvedIncludedWikiPath) === -1) { - $tw.loadWikiTiddlers(resolvedIncludedWikiPath,parentPaths); - } else { - console.log("Cannot recursively include wiki",resolvedIncludedWikiPath); - } - }); - } - // Load any plugins listed in the wiki info file - if(wikiInfo.plugins) { - var pluginBasePath = path.resolve($tw.boot.bootPath,$tw.config.pluginsPath); - for(var t=0; t