Skip to content

Commit b04d10a

Browse files
authored
Fix: improve error handling for invalid environment connections (#4552)
1 parent 6ab6963 commit b04d10a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

sqlmesh/core/config/connection.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1974,13 +1974,18 @@ def _connection_config_validator(
19741974
) -> ConnectionConfig | None:
19751975
if v is None or isinstance(v, ConnectionConfig):
19761976
return v
1977+
1978+
check_config_and_vars_msg = "\n\nVerify your config.yaml and environment variables."
1979+
19771980
try:
19781981
return parse_connection_config(v)
19791982
except pydantic.ValidationError as e:
19801983
raise ConfigError(
19811984
validation_error_message(e, f"Invalid '{v['type']}' connection config:")
1982-
+ "\n\nVerify your config.yaml and environment variables."
1985+
+ check_config_and_vars_msg
19831986
)
1987+
except ConfigError as e:
1988+
raise ConfigError(str(e) + check_config_and_vars_msg)
19841989

19851990

19861991
connection_config_validator: t.Callable = field_validator(

tests/core/test_config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ def test_load_config_from_env():
301301
)
302302

303303

304+
def test_load_config_from_env_fails():
305+
with mock.patch.dict(os.environ, {"SQLMESH__GATEWAYS__ABCDEF__CONNECTION__PASSWORD": "..."}):
306+
with pytest.raises(
307+
ConfigError,
308+
match="Missing connection type.\n\nVerify your config.yaml and environment variables.",
309+
):
310+
Config.parse_obj(load_config_from_env())
311+
312+
304313
def test_load_config_from_env_no_config_vars():
305314
with mock.patch.dict(
306315
os.environ,

0 commit comments

Comments
 (0)