|
14 | 14 | from sqlmesh.core.snapshot import SnapshotId, SnapshotTableInfo, Snapshot |
15 | 15 | from sqlmesh.utils import word_characters_only |
16 | 16 | from sqlmesh.utils.date import TimeLike, now_timestamp |
| 17 | +from sqlmesh.utils.errors import SQLMeshError |
17 | 18 | from sqlmesh.utils.jinja import JinjaMacroRegistry |
18 | 19 | from sqlmesh.utils.metaprogramming import Executable |
19 | 20 | from sqlmesh.utils.pydantic import PydanticModel, field_validator, ValidationInfo |
@@ -261,25 +262,35 @@ def execute_environment_statements( |
261 | 262 | end: t.Optional[TimeLike] = None, |
262 | 263 | execution_time: t.Optional[TimeLike] = None, |
263 | 264 | ) -> None: |
264 | | - rendered_expressions = [ |
265 | | - expr |
266 | | - for statements in environment_statements |
267 | | - for expr in render_statements( |
268 | | - statements=getattr(statements, runtime_stage.value), |
269 | | - dialect=adapter.dialect, |
270 | | - default_catalog=default_catalog, |
271 | | - python_env=statements.python_env, |
272 | | - jinja_macros=statements.jinja_macros, |
273 | | - snapshots=snapshots, |
274 | | - start=start, |
275 | | - end=end, |
276 | | - execution_time=execution_time, |
277 | | - environment_naming_info=environment_naming_info, |
278 | | - runtime_stage=runtime_stage, |
279 | | - engine_adapter=adapter, |
| 265 | + try: |
| 266 | + rendered_expressions = [ |
| 267 | + expr |
| 268 | + for statements in environment_statements |
| 269 | + for expr in render_statements( |
| 270 | + statements=getattr(statements, runtime_stage.value), |
| 271 | + dialect=adapter.dialect, |
| 272 | + default_catalog=default_catalog, |
| 273 | + python_env=statements.python_env, |
| 274 | + jinja_macros=statements.jinja_macros, |
| 275 | + snapshots=snapshots, |
| 276 | + start=start, |
| 277 | + end=end, |
| 278 | + execution_time=execution_time, |
| 279 | + environment_naming_info=environment_naming_info, |
| 280 | + runtime_stage=runtime_stage, |
| 281 | + engine_adapter=adapter, |
| 282 | + ) |
| 283 | + ] |
| 284 | + except Exception as e: |
| 285 | + raise SQLMeshError( |
| 286 | + f"An error occurred during rendering of the '{runtime_stage.value}' statements:\n\n{e}" |
280 | 287 | ) |
281 | | - ] |
282 | 288 | if rendered_expressions: |
283 | 289 | with adapter.transaction(): |
284 | 290 | for expr in rendered_expressions: |
285 | | - adapter.execute(expr) |
| 291 | + try: |
| 292 | + adapter.execute(expr) |
| 293 | + except Exception as e: |
| 294 | + raise SQLMeshError( |
| 295 | + f"An error occurred during execution of the following '{runtime_stage.value}' statement:\n\n{expr}\n\n{e}" |
| 296 | + ) |
0 commit comments