w3tecch / typeorm-seeding

🌱 A delightful way to seed test data into your database.
https://www.npmjs.com/package/typeorm-seeding
MIT License
887 stars 132 forks source link

Exceptions inside factories are hidden #113

Open jrr opened 3 years ago

jrr commented 3 years ago

I spent some time chasing down a bug today, where the only visible error was "Could not save entity". Here's the relevant code from typeorm-seeding:

https://github.com/w3tecch/typeorm-seeding/blob/4136b0e0f58a4ec13b17c717bd026043fbdf7ddd/src/entity-factory.ts#L46-L53

So there's a try/catch/throw, and the inner exception appears in the log, but it's not reflected in the thrown error. This is probably fine when you're seeding from an interactive terminal, but in my case it was a headless background process (a Cypress task), and it took some extra digging to get at that log output.

Instead, could typeorm-seeding rethrow the underlying exception, perhaps prepending something like "Could not save entity:" on the error message?

Would you be open to a contribution that does this?

RaphaelWoude commented 3 years ago

Sorry for the late response. We would for sure want to rethrow the exception here with the message and error. If you are still up to contribute, just sent a PR with the change.