fix(cli): do not silently drop errors in manage_users CLI

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson
2026-02-24 20:03:50 +01:00
parent 5d00de9892
commit 5cefc3cfe1

View File

@@ -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,6 +49,7 @@ async function createUser (argv) {
}
// Lets try to create, and check success
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']}`)
@@ -55,6 +57,14 @@ async function createUser (argv) {
} 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
}
}
}
// Using an async function to be able to use await inside
@@ -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)
});