Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: logging batch errors #1263

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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