From 6b5f6e3e79fa06e0b5c7e11fc15d110f68b68320 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Fri, 2 Mar 2018 12:37:36 +0200 Subject: [PATCH 1/2] Do not crash when user file can not be read Fixes #2128 Fixes #447 --- src/clientManager.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/clientManager.js b/src/clientManager.js index 9848ebbb..0306bcc2 100644 --- a/src/clientManager.js +++ b/src/clientManager.js @@ -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; } From 4b7a53c5e139ffecbed8101560d98871e412df46 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sat, 3 Mar 2018 18:07:31 +0200 Subject: [PATCH 2/2] Do not rethrow exception if user file failed to write --- src/clientManager.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/clientManager.js b/src/clientManager.js index 0306bcc2..24d359bd 100644 --- a/src/clientManager.js +++ b/src/clientManager.js @@ -153,8 +153,6 @@ ClientManager.prototype.updateUser = function(name, opts, callback) { if (callback) { callback(e); } - - throw e; } };