diff --git a/src/commands/seed/run.mts b/src/commands/seed/run.mts index 1a6ecf1..d2a7fd2 100644 --- a/src/commands/seed/run.mts +++ b/src/commands/seed/run.mts @@ -1,9 +1,11 @@ import type { ArgsDef, CommandDef } from 'citty' import { consola } from 'consola' import { colorize } from 'consola/utils' +import { process } from 'std-env' import { CommonArgs } from '../../arguments/common.mjs' import { usingSeeder } from '../../seeds/using-seeder.mjs' import { createSubcommand } from '../../utils/create-subcommand.mjs' +import { exitWithError, handleAggregateError } from '../../utils/error.mjs' const args = { ...CommonArgs, @@ -62,6 +64,11 @@ const BaseRunCommand = { }`, ) } + + if (error) { + handleAggregateError(error) + exitWithError(error) + } }, } satisfies CommandDef diff --git a/src/kysely/process-migration-result-set.mts b/src/kysely/process-migration-result-set.mts index d614f49..8164b86 100644 --- a/src/kysely/process-migration-result-set.mts +++ b/src/kysely/process-migration-result-set.mts @@ -2,6 +2,7 @@ import { consola } from 'consola' import { colorize } from 'consola/utils' import type { MigrationResultSet, Migrator } from 'kysely' import { process } from 'std-env' +import { exitWithError, handleAggregateError } from '../utils/error.mjs' import { getMigrations } from './get-migrations.mjs' export async function processMigrationResultSet( @@ -22,14 +23,8 @@ export async function processMigrationResultSet( }`, ) - if (error instanceof AggregateError) { - for (const subError of error.errors) { - consola.error(subError) - } - } - - process.exit?.(1) - throw error + handleAggregateError(error) + exitWithError(error) } if (!results?.length) { diff --git a/src/utils/error.mts b/src/utils/error.mts new file mode 100644 index 0000000..23c226e --- /dev/null +++ b/src/utils/error.mts @@ -0,0 +1,15 @@ +import { consola } from 'consola' +import { process } from 'std-env' + +export function handleAggregateError(error: unknown): void { + if (error instanceof AggregateError) { + for (const subError of error.errors) { + consola.error(subError) + } + } +} + +export function exitWithError(error: unknown): never { + process.exit?.(1) + throw error +}