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 models = require('../lib/models/')
const readline = require('readline-sync') const readline = require('readline-sync')
const minimist = require('minimist') const minimist = require('minimist')
const { ValidationError } = require('sequelize')
function showUsage (tips) { function showUsage (tips) {
console.log(`${tips} console.log(`${tips}
@@ -48,12 +49,21 @@ async function createUser (argv) {
} }
// Lets try to create, and check success // Lets try to create, and check success
const ref = await models.User.create({ email: argv['add'], password: pass }) try {
if (ref === undefined) { const ref = await models.User.create({ email: argv['add'], password: pass })
console.log(`Could not create user with email ${argv['add']}`) if (ref === undefined) {
process.exit(1) console.log(`Could not create user with email ${argv['add']}`)
} else { process.exit(1)
console.log(`Created user with email ${argv['add']}`) } 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 // Call respective processing functions
options[action](argv).then(function () { options[action](argv).then(function () {
process.exit(0); process.exit(0);
}).catch(err => {
console.error('An error occurred:', err)
process.exit(1)
}); });