Improve misleading error message "[TypeOrmModule] Unable to connect to the database."
eva-devs opened this issue · comments
Is there an existing issue that is already proposing this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe it
Any error occurring during MetaData build process will end in an error saying "Unable to connect to Database" due to the line
logger.error(Unable to connect to the database${connectionInfo}.${verboseMessage} Retrying (${errorCount +
1})..., error.stack);
in common/typeorm.utils.ts
In my case a wrong minification of class names after an upgrade showed up like this:
[Nest] 100086 - 18.01.2022, 08:12:50 ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
TypeORMError: Entity metadata for c#sites was not found. Check if you specified a correct entity object and if it's connected in the connection options.
at new TypeORMError (/home/ndh/projekte/eva/wks/src/error/TypeORMError.ts:7:9)
at /home/ndh/projekte/eva/wks/src/metadata-builder/EntityMetadataBuilder.ts:686:13
So I tried to find out why the database could not be connected instead of investigating the real cause.
Describe the solution you'd like
The log should show the real error (which is passed as argument) and not "guess" the reason for the failure.
Teachability, documentation, adoption, migration strategy
This is more an improvement than a feature.
What is the motivation / use case for changing the behavior?
Misleading error messages can cause very time consuming wrong analysis of errors
If you wait for the last reconnect attempt (10 tries) or you turn off retrying the connection, you'll get a detailed error message about why the connection failed
Well the point is: it was not a connection error at all. It was a MetaBuild Issue, typeorm could not retrieve the meta data for an entity relation. The connection was totally fine. You see the actual error in the second line of the log. But I assumed the second line error is caused by a connection error which was wrong.
If you have any ideas on how we could improve the error message to make it more descriptive, feel free to create a PR. Contributions are more than welcome!