From 0c99a633475904902ef18eadcc4bb1d9d715c1ec Mon Sep 17 00:00:00 2001 From: Richie Cahill Date: Tue, 21 Apr 2026 10:54:30 -0400 Subject: [PATCH] added DatabaseSetupError --- pipelines/orm/common.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pipelines/orm/common.py b/pipelines/orm/common.py index 6f86462..91bcd85 100644 --- a/pipelines/orm/common.py +++ b/pipelines/orm/common.py @@ -17,6 +17,10 @@ NAMING_CONVENTION = { } +class DatabaseSetupError(RuntimeError): + """Raised when database configuration is missing or invalid.""" + + def get_connection_info(name: str) -> tuple[str, str, str, str, str | None]: """Get connection info from environment variables.""" database = getenv(f"{name}_DB") @@ -27,11 +31,18 @@ def get_connection_info(name: str) -> tuple[str, str, str, str, str | None]: if None in (database, host, port, username): error = f"Missing environment variables for Postgres connection.\n{database=}\n{host=}\n{port=}\n{username=}\n" - raise ValueError(error) - return cast("tuple[str, str, str, str, str | None]", (database, host, port, username, password)) + raise DatabaseSetupError(error) + return cast( + "tuple[str, str, str, str, str | None]", + (database, host, port, username, password), + ) -def get_postgres_engine(*, name: str = "POSTGRES", pool_pre_ping: bool = True) -> Engine: +def get_postgres_engine( + *, + name: str = "POSTGRES", + pool_pre_ping: bool = True, +) -> Engine: """Create a SQLAlchemy engine from environment variables.""" database, host, port, username, password = get_connection_info(name)