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

Improve exception log messages #1519

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Changes from all commits
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
9 changes: 7 additions & 2 deletions tortoise/backends/asyncpg/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ async def create_connection(self, with_db: bool) -> None:
try:
self._pool = await self.create_pool(password=self.password, **self._template)
self.log.debug("Created connection pool %s with params: %s", self._pool, self._template)
except asyncpg.InvalidCatalogNameError:
raise DBConnectionError(f"Can't establish connection to database {self.database}")
except asyncpg.InvalidCatalogNameError as ex:
msg = "Can't establish connection to "
if with_db:
msg += f"database {self.database}"
else:
msg += f"default database. Verify environment PGDATABASE. Exception: {ex}"
raise DBConnectionError(msg)

async def create_pool(self, **kwargs) -> asyncpg.Pool:
return await asyncpg.create_pool(None, **kwargs)
Expand Down