From 3675958e303bc40f90883fbb030144e32397b1fe Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sun, 22 Jan 2012 17:37:21 +0000 Subject: [PATCH] Improvements to recipe error handling --- js/Recipe.js | 54 +++++++++++++++++++++++++++++++++++---------------- tiddlywiki.js | 2 +- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/js/Recipe.js b/js/Recipe.js index c0360d857..22f90460b 100755 --- a/js/Recipe.js +++ b/js/Recipe.js @@ -70,8 +70,7 @@ var Recipe = function(options,callback) { if(err) { me.callback(err); } else { - me.processRecipeFile(task.recipe,data.text,data.path); - callback(null); + callback(me.processRecipeFile(task.recipe,data.text,data.path)); } }); },1); @@ -79,20 +78,24 @@ var Recipe = function(options,callback) { this.tiddlerQueue = async.queue(function(task,callback) { me.readTiddlerFile(task.filepath,task.baseDir,function(err,data) { if(err) { - callback(err); + me.callback(err); } else { - if(task.recipeLine.fields) { - for(var t=0; t 0) { - throw "Unexpected indentation in recipe file"; + return "Unexpected indentation in recipe file '" + recipePath + "'"; } if(match.marker === "recipe") { var insertionPoint = recipe.push([]) - 1; @@ -237,19 +244,32 @@ Recipe.prototype.processRecipeFile = function(recipe,text,recipePath) { if(fieldLines.length > 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) { var me = this; // Read the tiddler file 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 var fields = { title: data.path diff --git a/tiddlywiki.js b/tiddlywiki.js index a2b1c3de6..89824901e 100644 --- a/tiddlywiki.js +++ b/tiddlywiki.js @@ -230,7 +230,7 @@ var processNextSwitch = function() { } csw.handler(s.args,function (err) { if(err) { - throw err; + throw "Error while executing option '--" + s.switchName + "' was:\n" + err; } process.nextTick(processNextSwitch); });