Skip to content

Commit d937838

Browse files
authored
fix: logging batch errors (#1263)
1 parent d7ca7c8 commit d937838

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/bin/cli.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ class BatchError extends Error {
4040
}
4141
}
4242

43+
function hasManyErrors(error: unknown): error is ManyError | BatchError {
44+
return error instanceof ManyError || error instanceof BatchError
45+
}
46+
4347
const makeTerminatingFunction =
4448
({ shouldThrow }) =>
45-
(error: Error) => {
49+
(error: any) => {
4650
if (shouldThrow) {
4751
throw error
4852
} else {
@@ -236,10 +240,18 @@ const createRun = ({ shouldThrow }) =>
236240
const successfulMigration = await new Listr(tasks).run()
237241
console.log(chalk`🎉 {bold.green Migration successful}`)
238242
return successfulMigration
239-
} catch (err) {
243+
} catch (err: unknown) {
240244
console.error(chalk`🚨 {bold.red Migration unsuccessful}`)
241-
console.error(chalk`{red ${err.message}}\n`)
242-
err.errors.forEach((err) => console.error(chalk`{red ${err}}\n\n`))
245+
246+
if (err instanceof Error) {
247+
console.error(chalk`{red ${err.message}}\n`)
248+
if (hasManyErrors(err) && Array.isArray(err.errors)) {
249+
err.errors.forEach((err: any) => console.error(chalk`{red ${err}}\n\n`))
250+
}
251+
} else {
252+
console.error(chalk`{red ${err}}\n`)
253+
}
254+
243255
await Promise.all(serverErrorsWritten)
244256
console.error(`Please check the errors log for more details: ${errorsFile}`)
245257
terminate(err)

0 commit comments

Comments
 (0)