call back with errors instead of throwing within the Storage module

This commit is contained in:
ansuz
2020-03-24 13:31:03 -04:00
parent 1240f4a2a5
commit e128683ffb
7 changed files with 30 additions and 12 deletions

View File

@@ -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) {