mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Better error handling in boot.js
This commit is contained in:
parent
9c066617a1
commit
c411ee5106
63
core/boot.js
63
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
|
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,30 +1015,31 @@ $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)) {
|
||||||
wikiInfo = JSON.parse(fs.readFileSync(wikiInfoPath,"utf8"));
|
$tw.utils.error("Missing tiddlywiki.info file at " + wikiPath);
|
||||||
// Load any parent wikis
|
}
|
||||||
if(wikiInfo.includeWikis) {
|
wikiInfo = JSON.parse(fs.readFileSync(wikiInfoPath,"utf8"));
|
||||||
parentPaths = parentPaths.slice(0);
|
// Load any parent wikis
|
||||||
parentPaths.push(wikiPath);
|
if(wikiInfo.includeWikis) {
|
||||||
$tw.utils.each(wikiInfo.includeWikis,function(includedWikiPath) {
|
parentPaths = parentPaths.slice(0);
|
||||||
var resolvedIncludedWikiPath = path.resolve(wikiPath,includedWikiPath);
|
parentPaths.push(wikiPath);
|
||||||
if(parentPaths.indexOf(resolvedIncludedWikiPath) === -1) {
|
$tw.utils.each(wikiInfo.includeWikis,function(includedWikiPath) {
|
||||||
$tw.loadWikiTiddlers(resolvedIncludedWikiPath,parentPaths);
|
var resolvedIncludedWikiPath = path.resolve(wikiPath,includedWikiPath);
|
||||||
} else {
|
if(parentPaths.indexOf(resolvedIncludedWikiPath) === -1) {
|
||||||
console.log("Cannot recursively include wiki",resolvedIncludedWikiPath);
|
$tw.loadWikiTiddlers(resolvedIncludedWikiPath,parentPaths);
|
||||||
}
|
} else {
|
||||||
});
|
$tw.utils.error("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);
|
// Load any plugins listed in the wiki info file
|
||||||
for(var t=0; t<wikiInfo.plugins.length; t++) {
|
if(wikiInfo.plugins) {
|
||||||
pluginFields = $tw.loadPluginFolder(path.resolve(pluginBasePath,"./" + wikiInfo.plugins[t]));
|
var pluginBasePath = path.resolve($tw.boot.bootPath,$tw.config.pluginsPath);
|
||||||
if(pluginFields) {
|
for(var t=0; t<wikiInfo.plugins.length; t++) {
|
||||||
$tw.wiki.addTiddler(pluginFields);
|
pluginFields = $tw.loadPluginFolder(path.resolve(pluginBasePath,"./" + wikiInfo.plugins[t]));
|
||||||
}
|
if(pluginFields) {
|
||||||
|
$tw.wiki.addTiddler(pluginFields);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user