From 4b39f0da46508c8802fdfe726721fbad62281af1 Mon Sep 17 00:00:00 2001 From: cel Date: Fri, 6 Mar 2020 22:53:09 -0500 Subject: drafts: better error handling; skip dotfiles --- lib/app.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/app.js') diff --git a/lib/app.js b/lib/app.js index f223745..f45e6f9 100644 --- a/lib/app.js +++ b/lib/app.js @@ -1512,11 +1512,12 @@ App.prototype.saveDraft = function (id, url, form, content, cb) { App.prototype.getDraft = function (id, cb) { var self = this - fs.readFile(path.join(self.draftsDir, id), 'utf8', function (err, data) { + var filename = path.join(self.draftsDir, id) + fs.readFile(filename, 'utf8', function (err, data) { if (err) return cb(err) var draft try { draft = JSON.parse(data) } - catch(e) { return cb(e) } + catch(e) { return cb(new Error('JSON Error reading ' + filename + ': ' + e.stack)) } draft.id = id cb(null, draft) }) @@ -1533,6 +1534,9 @@ function compareMtime(a, b) { function statAll(files, dir, cb) { pull( pull.values(files), + pull.filter(function (file) { + return !/^\./.test(file) + }), paramap(function (file, cb) { fs.stat(path.join(dir, file), function (err, stats) { if (err) return cb(err) -- cgit v1.2.3