1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

Improvements to recipe error handling

This commit is contained in:
Jeremy Ruston 2012-01-22 17:37:21 +00:00
parent 5d1cf97134
commit 3675958e30
2 changed files with 38 additions and 18 deletions

View File

@ -70,8 +70,7 @@ var Recipe = function(options,callback) {
if(err) { if(err) {
me.callback(err); me.callback(err);
} else { } else {
me.processRecipeFile(task.recipe,data.text,data.path); callback(me.processRecipeFile(task.recipe,data.text,data.path));
callback(null);
} }
}); });
},1); },1);
@ -79,7 +78,10 @@ var Recipe = function(options,callback) {
this.tiddlerQueue = async.queue(function(task,callback) { this.tiddlerQueue = async.queue(function(task,callback) {
me.readTiddlerFile(task.filepath,task.baseDir,function(err,data) { me.readTiddlerFile(task.filepath,task.baseDir,function(err,data) {
if(err) { if(err) {
callback(err); me.callback(err);
} else {
if(data.length === 0) {
callback("Tiddler file '" + task.filepath + "' does not contain any tiddlers");
} else { } else {
if(task.recipeLine.fields) { if(task.recipeLine.fields) {
for(var t=0; t<data.length; t++) { for(var t=0; t<data.length; t++) {
@ -94,6 +96,7 @@ var Recipe = function(options,callback) {
Array.prototype.push.apply(task.recipeLine.tiddlers,data); Array.prototype.push.apply(task.recipeLine.tiddlers,data);
callback(null); callback(null);
} }
}
}); });
},1); },1);
// Called when all the recipes have been loaded // Called when all the recipes have been loaded
@ -198,6 +201,10 @@ Recipe.prototype.sortTiddlersForMarker = function(marker) {
/* /*
Process the contents of a recipe file Process the contents of a recipe file
recipe: a reference to the array in which to store the recipe contents
text: the text of the recipe file
recipePath: the full pathname used to reach the recipe file
The return value is `null` if the operation succeeded, or an error string if not
*/ */
Recipe.prototype.processRecipeFile = function(recipe,text,recipePath) { Recipe.prototype.processRecipeFile = function(recipe,text,recipePath) {
var matchLine = function(linetext) { var matchLine = function(linetext) {
@ -217,7 +224,7 @@ Recipe.prototype.processRecipeFile = function(recipe,text,recipePath) {
match = matchLine(linetext); match = matchLine(linetext);
if(match && !match.comment) { if(match && !match.comment) {
if(match.indent.length > 0) { if(match.indent.length > 0) {
throw "Unexpected indentation in recipe file"; return "Unexpected indentation in recipe file '" + recipePath + "'";
} }
if(match.marker === "recipe") { if(match.marker === "recipe") {
var insertionPoint = recipe.push([]) - 1; var insertionPoint = recipe.push([]) - 1;
@ -237,19 +244,32 @@ Recipe.prototype.processRecipeFile = function(recipe,text,recipePath) {
if(fieldLines.length > 0) { if(fieldLines.length > 0) {
fields = this.store.deserializeTiddlers("application/x-tiddler",fieldLines.join("\n"),{})[0]; fields = this.store.deserializeTiddlers("application/x-tiddler",fieldLines.join("\n"),{})[0];
} }
recipe.push({marker: match.marker, filepath: match.value, baseDir: path.dirname(recipePath), fields: fields}); recipe.push({
marker: match.marker,
filepath: match.value,
baseDir: path.dirname(recipePath),
fields: fields});
} }
} }
} }
return null;
}; };
// Read a tiddler file and callback with an array of hashmaps of tiddler fields. For single /*
// tiddler files it also looks for an accompanying .meta file Read a tiddler file and callback with an array of hashmaps of tiddler fields. For single
tiddler files it also looks for an accompanying .meta file
filepath: the filepath to the tiddler file (possibly relative)
baseDir: the base directory from which the filepath is taken
callback: called on completion as callback(err,data) where data is an array of tiddler fields
*/
Recipe.prototype.readTiddlerFile = function(filepath,baseDir,callback) { Recipe.prototype.readTiddlerFile = function(filepath,baseDir,callback) {
var me = this; var me = this;
// Read the tiddler file // Read the tiddler file
retrieveFile(filepath,baseDir,function(err,data) { retrieveFile(filepath,baseDir,function(err,data) {
if (err) throw err; if (err) {
callback(err);
return;
}
// Use the filepath as the default title for the tiddler // Use the filepath as the default title for the tiddler
var fields = { var fields = {
title: data.path title: data.path

View File

@ -230,7 +230,7 @@ var processNextSwitch = function() {
} }
csw.handler(s.args,function (err) { csw.handler(s.args,function (err) {
if(err) { if(err) {
throw err; throw "Error while executing option '--" + s.switchName + "' was:\n" + err;
} }
process.nextTick(processNextSwitch); process.nextTick(processNextSwitch);
}); });