Make sure CLI does not crash on undefined.length
when we figured out users could not be read already
This commit is contained in:
parent
cdbefd3905
commit
ed68ff4a34
@ -35,6 +35,12 @@ ClientManager.prototype.autoloadUsers = function() {
|
||||
const users = this.getUsers();
|
||||
const noUsersWarning = `There are currently no users. Create one with ${colors.bold("lounge add <name>")}.`;
|
||||
|
||||
// There was an error, already logged, but we have to crash the server as
|
||||
// user directory could not be accessed
|
||||
if (users === undefined) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!users.length) {
|
||||
log.info(noUsersWarning);
|
||||
}
|
||||
@ -91,7 +97,7 @@ ClientManager.prototype.getUsers = function() {
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
log.error("Failed to get users", e);
|
||||
log.error(`Failed to get users (${e})`);
|
||||
return;
|
||||
}
|
||||
return users;
|
||||
|
@ -18,6 +18,10 @@ program
|
||||
const manager = new ClientManager();
|
||||
const users = manager.getUsers();
|
||||
|
||||
if (users === undefined) { // There was an error, already logged
|
||||
return;
|
||||
}
|
||||
|
||||
if (users.indexOf(name) !== -1) {
|
||||
log.error(`User ${colors.bold(name)} already exists.`);
|
||||
return;
|
||||
|
@ -13,6 +13,11 @@ program
|
||||
.on("--help", Utils.extraHelp)
|
||||
.action(function(name) {
|
||||
var users = new ClientManager().getUsers();
|
||||
|
||||
if (users === undefined) { // There was an error, already logged
|
||||
return;
|
||||
}
|
||||
|
||||
if (users.indexOf(name) === -1) {
|
||||
log.error(`User ${colors.bold(name)} does not exist.`);
|
||||
return;
|
||||
|
@ -16,6 +16,11 @@ program
|
||||
}
|
||||
|
||||
var users = new ClientManager().getUsers();
|
||||
|
||||
if (users === undefined) { // There was an error, already logged
|
||||
return;
|
||||
}
|
||||
|
||||
if (!users.length) {
|
||||
log.info(`There are currently no users. Create one with ${colors.bold("lounge add <name>")}.`);
|
||||
} else {
|
||||
|
@ -10,10 +10,15 @@ program
|
||||
.description("Remove an existing user")
|
||||
.on("--help", Utils.extraHelp)
|
||||
.action(function(name) {
|
||||
var manager = new ClientManager();
|
||||
const manager = new ClientManager();
|
||||
|
||||
try {
|
||||
if (manager.removeUser(name)) {
|
||||
log.info(`User ${colors.bold(name)} removed.`);
|
||||
} else {
|
||||
log.error(`User ${colors.bold(name)} does not exist.`);
|
||||
}
|
||||
} catch (e) {
|
||||
// There was an error, already logged
|
||||
}
|
||||
});
|
||||
|
@ -13,6 +13,11 @@ program
|
||||
.on("--help", Utils.extraHelp)
|
||||
.action(function(name) {
|
||||
var users = new ClientManager().getUsers();
|
||||
|
||||
if (users === undefined) { // There was an error, already logged
|
||||
return;
|
||||
}
|
||||
|
||||
if (users.indexOf(name) === -1) {
|
||||
log.error(`User ${colors.bold(name)} does not exist.`);
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user