Skip to content

Commit 97314bc

Browse files
committed
fix seed run error handling.
1 parent 0e941ae commit 97314bc

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/commands/seed/run.mts

+7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import type { ArgsDef, CommandDef } from 'citty'
22
import { consola } from 'consola'
33
import { colorize } from 'consola/utils'
4+
import { process } from 'std-env'
45
import { CommonArgs } from '../../arguments/common.mjs'
56
import { usingSeeder } from '../../seeds/using-seeder.mjs'
67
import { createSubcommand } from '../../utils/create-subcommand.mjs'
8+
import { exitWithError, handleAggregateError } from '../../utils/error.mjs'
79

810
const args = {
911
...CommonArgs,
@@ -62,6 +64,11 @@ const BaseRunCommand = {
6264
}`,
6365
)
6466
}
67+
68+
if (error) {
69+
handleAggregateError(error)
70+
exitWithError(error)
71+
}
6572
},
6673
} satisfies CommandDef<typeof args>
6774

src/kysely/process-migration-result-set.mts

+3-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { consola } from 'consola'
22
import { colorize } from 'consola/utils'
33
import type { MigrationResultSet, Migrator } from 'kysely'
44
import { process } from 'std-env'
5+
import { exitWithError, handleAggregateError } from '../utils/error.mjs'
56
import { getMigrations } from './get-migrations.mjs'
67

78
export async function processMigrationResultSet(
@@ -22,14 +23,8 @@ export async function processMigrationResultSet(
2223
}`,
2324
)
2425

25-
if (error instanceof AggregateError) {
26-
for (const subError of error.errors) {
27-
consola.error(subError)
28-
}
29-
}
30-
31-
process.exit?.(1)
32-
throw error
26+
handleAggregateError(error)
27+
exitWithError(error)
3328
}
3429

3530
if (!results?.length) {

src/utils/error.mts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { consola } from 'consola'
2+
import { process } from 'std-env'
3+
4+
export function handleAggregateError(error: unknown): void {
5+
if (error instanceof AggregateError) {
6+
for (const subError of error.errors) {
7+
consola.error(subError)
8+
}
9+
}
10+
}
11+
12+
export function exitWithError(error: unknown): never {
13+
process.exit?.(1)
14+
throw error
15+
}

0 commit comments

Comments
 (0)