Skip to content

Commit

Permalink
fix: logging batch errors
Browse files Browse the repository at this point in the history
  • Loading branch information
marcolink committed Oct 24, 2023
1 parent d7ca7c8 commit 3c1497d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ class BatchError extends Error {
}
}

function hasManyErrors(error: unknown): error is ManyError | BatchError {
return error instanceof ManyError || error instanceof BatchError
}

const makeTerminatingFunction =
({ shouldThrow }) =>
(error: Error) => {
(error: any) => {
if (shouldThrow) {
throw error
} else {
Expand Down Expand Up @@ -236,10 +240,18 @@ const createRun = ({ shouldThrow }) =>
const successfulMigration = await new Listr(tasks).run()
console.log(chalk`🎉 {bold.green Migration successful}`)
return successfulMigration
} catch (err) {
} catch (err: unknown) {
console.error(chalk`🚨 {bold.red Migration unsuccessful}`)
console.error(chalk`{red ${err.message}}\n`)
err.errors.forEach((err) => console.error(chalk`{red ${err}}\n\n`))

if (err instanceof Error) {
console.error(chalk`{red ${err.message}}\n`)
if (hasManyErrors(err) && Array.isArray(err.errors)) {
err.errors.forEach((err: any) => console.error(chalk`{red ${err}}\n\n`))
}
} else {
console.error(chalk`{red ${err}}\n`)
}

await Promise.all(serverErrorsWritten)
console.error(`Please check the errors log for more details: ${errorsFile}`)
terminate(err)
Expand Down

0 comments on commit 3c1497d

Please sign in to comment.