From bdd5aa934355b064a101849aa1118c988e0df7f2 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Thu, 23 Jun 2016 16:19:00 +0100 Subject: [PATCH] Trap missing tiddlers in savetiddler command --- core/modules/commands/savetiddler.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/core/modules/commands/savetiddler.js b/core/modules/commands/savetiddler.js index b6c6ac376..efc484ec7 100644 --- a/core/modules/commands/savetiddler.js +++ b/core/modules/commands/savetiddler.js @@ -32,13 +32,17 @@ Command.prototype.execute = function() { path = require("path"), title = this.params[0], filename = path.resolve(this.commander.outputPath,this.params[1]), - tiddler = this.commander.wiki.getTiddler(title), - type = tiddler.fields.type || "text/vnd.tiddlywiki", - contentTypeInfo = $tw.config.contentTypeInfo[type] || {encoding: "utf8"}; - $tw.utils.createFileDirectories(filename); - fs.writeFile(filename,tiddler.fields.text,contentTypeInfo.encoding,function(err) { - self.callback(err); - }); + tiddler = this.commander.wiki.getTiddler(title); + if(tiddler) { + var type = tiddler.fields.type || "text/vnd.tiddlywiki", + contentTypeInfo = $tw.config.contentTypeInfo[type] || {encoding: "utf8"}; + $tw.utils.createFileDirectories(filename); + fs.writeFile(filename,tiddler.fields.text,contentTypeInfo.encoding,function(err) { + self.callback(err); + }); + } else { + return "Missing tiddler: " + title; + } return null; };