This commit is contained in:
Calvin Montgomery 2017-03-01 20:46:01 -08:00
parent a80512aa60
commit d4db459ff9
3 changed files with 13 additions and 15 deletions

View File

@ -2,7 +2,7 @@
"author": "Calvin Montgomery", "author": "Calvin Montgomery",
"name": "CyTube", "name": "CyTube",
"description": "Online media synchronizer and chat", "description": "Online media synchronizer and chat",
"version": "3.29.0", "version": "3.30.0",
"repository": { "repository": {
"url": "http://github.com/calzoneman/sync" "url": "http://github.com/calzoneman/sync"
}, },

View File

@ -91,10 +91,8 @@ function Channel(name) {
var self = this; var self = this;
db.channels.load(this, function (err) { db.channels.load(this, function (err) {
if (err && err !== "Channel is not registered") { if (err && err !== "Channel is not registered") {
self.emit("loadFail", "Failed to load channel data from the database"); self.emit("loadFail", "Failed to load channel data from the database. Please try again later.");
// Force channel to be unloaded, so that it will load properly when self.setFlag(Flags.C_ERROR);
// the database connection comes back
self.emit("empty");
return; return;
} else { } else {
self.initModules(); self.initModules();
@ -197,14 +195,11 @@ Channel.prototype.loadState = function () {
} }
const self = this; const self = this;
function errorLoad(msg) { function errorLoad(msg, suggestTryAgain = true) {
if (self.modules.customization) { const extra = suggestTryAgain ? " Please try again later." : "";
self.modules.customization.load({ self.emit("loadFail", "Failed to load channel data from the database: " +
motd: msg msg + extra);
}); self.setFlag(Flags.C_ERROR);
}
self.setFlag(Flags.C_READY | Flags.C_ERROR);
} }
ChannelStore.load(this.id, this.uniqueName).then(data => { ChannelStore.load(this.id, this.uniqueName).then(data => {
@ -224,7 +219,7 @@ Channel.prototype.loadState = function () {
"for assistance."; "for assistance.";
Logger.errlog.log(err.stack); Logger.errlog.log(err.stack);
errorLoad(message); errorLoad(message, false);
}).catch(err => { }).catch(err => {
if (err.code === 'ENOENT') { if (err.code === 'ENOENT') {
Object.keys(this.modules).forEach(m => { Object.keys(this.modules).forEach(m => {
@ -235,7 +230,7 @@ Channel.prototype.loadState = function () {
} else { } else {
const message = "An error occurred when loading this channel's data from " + const message = "An error occurred when loading this channel's data from " +
"disk. Please contact an administrator for assistance. " + "disk. Please contact an administrator for assistance. " +
`The error was: ${err}`; `The error was: ${err}.`;
Logger.errlog.log(err.stack); Logger.errlog.log(err.stack);
errorLoad(message); errorLoad(message);

View File

@ -216,6 +216,9 @@ Server.prototype.getChannel = function (name) {
c.on("empty", function () { c.on("empty", function () {
self.unloadChannel(c); self.unloadChannel(c);
}); });
c.waitFlag(Flags.C_ERROR, () => {
self.unloadChannel(c, { skipSave: true });
});
self.channels.push(c); self.channels.push(c);
return c; return c;
}; };