Skip to content

Commit e0e7366

Browse files
committed
Improve error message
1 parent 526af33 commit e0e7366

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

sqlmesh/core/context.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ def resolve_table(self, model_name: str) -> str:
214214
"""
215215
model_name = normalize_model_name(model_name, self.default_catalog, self.default_dialect)
216216

217+
if model_name not in self._model_tables:
218+
model_name_list = "\n".join(list(self._model_tables))
219+
logger.debug(
220+
f"'{model_name}' not found in model to table mapping. Available model names: \n{model_name_list}"
221+
)
222+
raise SQLMeshError(
223+
f"Unable to find a table mapping for model '{model_name}'. Has it been spelled correctly?"
224+
)
225+
217226
# We generate SQL for the default dialect because the table name may be used in a
218227
# fetchdf call and so the quotes need to be correct (eg. backticks for bigquery)
219228
return parse_one(self._model_tables[model_name]).sql(

tests/core/test_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3082,4 +3082,7 @@ def execute(
30823082
assert '"GOLD"."SUSHI"."FOO"' in test.context._model_tables
30833083
assert '"GOLD"."SUSHI"."BAR"' in test.context._model_tables
30843084

3085+
with pytest.raises(SQLMeshError, match=r"Unable to find a table mapping"):
3086+
test.context.resolve_table("silver.sushi.bar")
3087+
30853088
_check_successful_or_raise(test.run())

0 commit comments

Comments
 (0)