Skip to content

Commit

Permalink
fix seed run error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
igalklebanov committed Jul 14, 2024
1 parent 0e941ae commit 97314bc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/commands/seed/run.mts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -62,6 +64,11 @@ const BaseRunCommand = {
}`,
)
}

if (error) {
handleAggregateError(error)
exitWithError(error)
}
},
} satisfies CommandDef<typeof args>

Expand Down
11 changes: 3 additions & 8 deletions src/kysely/process-migration-result-set.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions src/utils/error.mts
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 97314bc

Please sign in to comment.