Do not crash when user file can not be read

Fixes #2128
Fixes #447
This commit is contained in:
Pavel Djundik 2018-03-02 12:37:36 +02:00
parent e0b15f18e1
commit 6b5f6e3e79
1 changed files with 9 additions and 9 deletions

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");
@ -185,6 +179,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;
}