1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-18 11:29:55 +00:00

Better error handling in boot.js

This commit is contained in:
Jeremy Ruston 2013-03-28 14:06:50 +00:00
parent 9c066617a1
commit c411ee5106

View File

@ -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 Check if an object has a property
*/ */
@ -741,7 +749,7 @@ $tw.modules.execute = function(moduleName,moduleRoot) {
exports = {}, exports = {},
moduleInfo = $tw.modules.titles[name]; moduleInfo = $tw.modules.titles[name];
if(!moduleInfo) { 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(!moduleInfo.exports) {
if(typeof moduleInfo.definition === "string") { // String if(typeof moduleInfo.definition === "string") { // String
@ -890,7 +898,7 @@ $tw.modules.execute = function(moduleName,moduleRoot) {
moduleInfo.exports = moduleInfo.definition; moduleInfo.exports = moduleInfo.definition;
} }
} catch(e) { } 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 // Return the exports of the module
@ -1007,8 +1015,10 @@ $tw.loadWikiTiddlers = function(wikiPath,parentPaths) {
var wikiInfoPath = path.resolve(wikiPath,$tw.config.wikiInfo), var wikiInfoPath = path.resolve(wikiPath,$tw.config.wikiInfo),
wikiInfo = {}, wikiInfo = {},
pluginFields; pluginFields;
// Load the wiki info file // Bail if we don't have a wiki info file
if(fs.existsSync(wikiInfoPath)) { if(!fs.existsSync(wikiInfoPath)) {
$tw.utils.error("Missing tiddlywiki.info file at " + wikiPath);
}
wikiInfo = JSON.parse(fs.readFileSync(wikiInfoPath,"utf8")); wikiInfo = JSON.parse(fs.readFileSync(wikiInfoPath,"utf8"));
// Load any parent wikis // Load any parent wikis
if(wikiInfo.includeWikis) { if(wikiInfo.includeWikis) {
@ -1019,7 +1029,7 @@ $tw.loadWikiTiddlers = function(wikiPath,parentPaths) {
if(parentPaths.indexOf(resolvedIncludedWikiPath) === -1) { if(parentPaths.indexOf(resolvedIncludedWikiPath) === -1) {
$tw.loadWikiTiddlers(resolvedIncludedWikiPath,parentPaths); $tw.loadWikiTiddlers(resolvedIncludedWikiPath,parentPaths);
} else { } else {
console.log("Cannot recursively include wiki",resolvedIncludedWikiPath); $tw.utils.error("Cannot recursively include wiki " + resolvedIncludedWikiPath);
} }
}); });
} }
@ -1033,7 +1043,6 @@ $tw.loadWikiTiddlers = function(wikiPath,parentPaths) {
} }
} }
} }
}
// Load the wiki files, registering them as writable // Load the wiki files, registering them as writable
var resolvedWikiPath = path.resolve(wikiPath,$tw.config.wikiTiddlersSubDir); var resolvedWikiPath = path.resolve(wikiPath,$tw.config.wikiTiddlersSubDir);
$tw.utils.each($tw.loadTiddlersFromPath(resolvedWikiPath),function(tiddlerFile) { $tw.utils.each($tw.loadTiddlersFromPath(resolvedWikiPath),function(tiddlerFile) {
@ -1113,7 +1122,7 @@ $tw.boot.startup = function() {
$tw.packageInfo = JSON.parse(fs.readFileSync($tw.boot.bootPath + "/../package.json")); $tw.packageInfo = JSON.parse(fs.readFileSync($tw.boot.bootPath + "/../package.json"));
// Check node version number // Check node version number
if($tw.utils.checkVersions($tw.packageInfo.engines.node.substr(2),process.version.substr(1))) { if($tw.utils.checkVersions($tw.packageInfo.engines.node.substr(2),process.version.substr(1))) {
throw "TiddlyWiki5 requires node.js version " + $tw.packageInfo.engine.node; $tw.utils.error("TiddlyWiki5 requires node.js version " + $tw.packageInfo.engine.node);
} }
} }
// Add file extension information // Add file extension information