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

Exceptions inside factories are hidden #113

Open
jrr opened this issue Jan 26, 2021 · 1 comment
Open

Exceptions inside factories are hidden #113

jrr opened this issue Jan 26, 2021 · 1 comment

Comments

@jrr
Copy link

jrr commented Jan 26, 2021

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:

try {
const entity = await this.makeEnity(overrideParams, true)
return await em.save<Entity>(entity)
} catch (error) {
const message = 'Could not save entity'
printError(message, error)
throw new Error(message)
}

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
Copy link
Collaborator

RaphaelWoude commented Sep 9, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants