Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/umzug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ export class MigrationError extends errorCause.ErrorWithCause<unknown> {
}

private static errorString(cause: unknown) {
return cause instanceof Error
? `Original error: ${cause.message}`
: `Non-error value thrown. See info for full props: ${cause as string}`
if (cause instanceof Error) return `Original error: ${cause.message}`
const msg = 'Non-error value thrown. See info for full props'
try {
return `${msg}: ${String(cause)}`
} catch {
//Null prototype object 'cause' would end up here
return msg
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions test/umzug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,10 @@ describe('alternate migration inputs', () => {
async up() {},

async down() {
throw 'Some cryptic failure'
// This kind of error is thrown in MikroOrm migrations
const reallyCrypticFailure: any = Object.create(null)
reallyCrypticFailure.customText = 'Some cryptic failure'
throw reallyCrypticFailure
},
},
{
Expand All @@ -705,7 +708,7 @@ describe('alternate migration inputs', () => {
)

await expect(umzug.down()).rejects.toThrowErrorMatchingInlineSnapshot(
`"Migration m1 (down) failed: Non-error value thrown. See info for full props: Some cryptic failure"`,
`"Migration m1 (down) failed: Non-error value thrown. See info for full props"`,
)
})

Expand Down
Loading