From 5cefc3cfe13254c04aad54e1740422c7ae6915de Mon Sep 17 00:00:00 2001 From: Erik Michelson Date: Tue, 24 Feb 2026 20:03:50 +0100 Subject: [PATCH] fix(cli): do not silently drop errors in manage_users CLI Signed-off-by: Erik Michelson --- bin/manage_users | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/bin/manage_users b/bin/manage_users index 6f3af2a0..5f3c3578 100755 --- a/bin/manage_users +++ b/bin/manage_users @@ -7,6 +7,7 @@ logger.transports.forEach((transport) => transport.level = 'warning') const models = require('../lib/models/') const readline = require('readline-sync') const minimist = require('minimist') +const { ValidationError } = require('sequelize') function showUsage (tips) { console.log(`${tips} @@ -48,12 +49,21 @@ async function createUser (argv) { } // Lets try to create, and check success - const ref = await models.User.create({ email: argv['add'], password: pass }) - if (ref === undefined) { - console.log(`Could not create user with email ${argv['add']}`) - process.exit(1) - } else { - console.log(`Created user with email ${argv['add']}`) + try { + const ref = await models.User.create({ email: argv['add'], password: pass }) + if (ref === undefined) { + console.log(`Could not create user with email ${argv['add']}`) + process.exit(1) + } else { + console.log(`Created user with email ${argv['add']}`) + } + } catch (err) { + if (err instanceof ValidationError) { + console.log('Could not create user, since the email address is invalid.') + process.exit(1) + } else { + throw err + } } } @@ -117,4 +127,7 @@ if (typeof argv[action] !== 'string') { // Call respective processing functions options[action](argv).then(function () { process.exit(0); +}).catch(err => { + console.error('An error occurred:', err) + process.exit(1) });