diff --git a/lib/compute-index.js b/lib/compute-index.js index 6cf0c3657..b246b0c9c 100644 --- a/lib/compute-index.js +++ b/lib/compute-index.js @@ -15,7 +15,8 @@ const init = function (config, cb) { return void cb('E_INVALID_CONFIG'); } - Store.create(config, function (_store) { + Store.create(config, function (err, _store) { + if (err) { return void cb(err); } store = _store; cb(); }); diff --git a/lib/historyKeeper.js b/lib/historyKeeper.js index 23dbf5fd1..2f6043dfd 100644 --- a/lib/historyKeeper.js +++ b/lib/historyKeeper.js @@ -215,12 +215,14 @@ module.exports.create = function (config, cb) { // create a pin store Store.create({ filePath: pinPath, - }, w(function (s) { + }, w(function (err, s) { + if (err) { throw err; } Env.pinStore = s; })); // create a channel store - Store.create(config, w(function (_store) { + Store.create(config, w(function (err, _store) { + if (err) { throw err; } config.store = _store; Env.msgStore = _store; // API used by rpc Env.store = _store; // API used by historyKeeper diff --git a/lib/log.js b/lib/log.js index 756da8734..d4ffcad56 100644 --- a/lib/log.js +++ b/lib/log.js @@ -101,7 +101,10 @@ Logger.create = function (config, cb) { Store.create({ filePath: config.logPath, - }, function (store) { + }, function (err, store) { + if (err) { + throw err; + } ctx.store = store; var logger = createMethods(ctx); logger.shutdown = function () { diff --git a/lib/storage/file.js b/lib/storage/file.js index 25ff021f0..e040bf807 100644 --- a/lib/storage/file.js +++ b/lib/storage/file.js @@ -951,7 +951,9 @@ var trimChannel = function (env, channelName, hash, _cb) { }); }; -module.exports.create = function (conf, cb) { +module.exports.create = function (conf, _cb) { + var cb = Util.once(Util.mkAsync(_cb)); + var env = { root: conf.filePath || './datastore', archiveRoot: conf.archivePath || './data/archive', @@ -984,18 +986,19 @@ module.exports.create = function (conf, cb) { // make sure the store's directory exists Fse.mkdirp(env.root, PERMISSIVE, w(function (err) { if (err && err.code !== 'EEXIST') { - throw err; // XXX + w.abort(); + return void cb(err); } })); // make sure the cold storage directory exists Fse.mkdirp(env.archiveRoot, PERMISSIVE, w(function (err) { if (err && err.code !== 'EEXIST') { - throw err; // XXX + w.abort(); + return void cb(err); } })); }).nThen(function () { - // XXX leave a place for an error - cb({ + cb(void 0, { // OLDER METHODS // write a new message to a log message: function (channelName, content, cb) { diff --git a/scripts/diagnose-archive-conflicts.js b/scripts/diagnose-archive-conflicts.js index 0e75f4abe..7e5ee92bc 100644 --- a/scripts/diagnose-archive-conflicts.js +++ b/scripts/diagnose-archive-conflicts.js @@ -8,7 +8,11 @@ var Log; nThen(function (w) { // load the store which will be used for iterating over channels // and performing operations like archival and deletion - Store.create(config, w(function (_) { + Store.create(config, w(function (err, _) { + if (err) { + w.abort(); + throw err; + } store = _; })); diff --git a/scripts/evict-inactive.js b/scripts/evict-inactive.js index 18730fd1e..a3a595ca4 100644 --- a/scripts/evict-inactive.js +++ b/scripts/evict-inactive.js @@ -34,7 +34,11 @@ var msSinceStart = function () { nThen(function (w) { // load the store which will be used for iterating over channels // and performing operations like archival and deletion - Store.create(config, w(function (_) { + Store.create(config, w(function (err, _) { + if (err) { + w.abort(); + throw err; + } store = _; })); // load the list of pinned files so you know which files // should not be archived or deleted diff --git a/scripts/restore-archived.js b/scripts/restore-archived.js index 3f68b607e..4ee01c02f 100644 --- a/scripts/restore-archived.js +++ b/scripts/restore-archived.js @@ -8,7 +8,8 @@ var Log; nThen(function (w) { // load the store which will be used for iterating over channels // and performing operations like archival and deletion - Store.create(config, w(function (_) { + Store.create(config, w(function (err, _) { + if (err) { throw err; } store = _; }));