typeorm-seeding icon indicating copy to clipboard operation
typeorm-seeding copied to clipboard

Exceptions inside factories are hidden

Open jrr opened this issue 3 years ago • 1 comments

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?

jrr avatar Jan 26 '21 22:01 jrr

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.

RaphaelWoude avatar Sep 09 '21 13:09 RaphaelWoude