Merge pull request #2143 from thelounge/xpaw/fix-2128

Do not crash when user file can not be read or written
This commit is contained in:
Pavel Djundik 2018-03-03 23:03:57 +02:00 committed by GitHub
commit 68cc9a2e28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -132,13 +132,7 @@ ClientManager.prototype.updateUser = function(name, opts, callback) {
const user = readUserConfig(name);
if (!user) {
log.error(`Tried to update invalid user ${colors.green(name)}. This is most likely a bug.`);
if (callback) {
callback(true);
}
return false;
return callback ? callback(true) : false;
}
const currentUser = JSON.stringify(user, null, "\t");
@ -159,8 +153,6 @@ ClientManager.prototype.updateUser = function(name, opts, callback) {
if (callback) {
callback(e);
}
throw e;
}
};
@ -185,6 +177,12 @@ function readUserConfig(name) {
return false;
}
const data = fs.readFileSync(userPath, "utf-8");
return JSON.parse(data);
try {
const data = fs.readFileSync(userPath, "utf-8");
return JSON.parse(data);
} catch (e) {
log.error(`Failed to read user ${colors.bold(name)}: ${e}`);
}
return false;
}