Skip to content

Commit a2a9793

Browse files
authored
feat: add custom exception for signal eval errors (#4141)
1 parent 7271e8f commit a2a9793

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

sqlmesh/core/snapshot/definition.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
validate_date_range,
3939
yesterday,
4040
)
41-
from sqlmesh.utils.errors import SQLMeshError
41+
from sqlmesh.utils.errors import SQLMeshError, SignalEvalError
4242
from sqlmesh.utils.metaprogramming import prepare_env, print_exception
4343
from sqlmesh.utils.hashing import hash_data
4444
from sqlmesh.utils.pydantic import PydanticModel, field_validator
@@ -2171,19 +2171,19 @@ def _check_ready_intervals(
21712171
provided_kwargs=(kwargs or {}),
21722172
context=context,
21732173
)
2174-
except Exception:
2175-
raise SQLMeshError("Error evaluating signal")
2174+
except Exception as ex:
2175+
raise SignalEvalError("Error evaluating signal") from ex
21762176

21772177
if isinstance(ready_intervals, bool):
21782178
if not ready_intervals:
21792179
batch = []
21802180
elif isinstance(ready_intervals, list):
21812181
for i in ready_intervals:
21822182
if i not in batch:
2183-
raise SQLMeshError(f"Unknown interval {i} for signal")
2183+
raise SignalEvalError(f"Unknown interval {i} for signal")
21842184
batch = ready_intervals
21852185
else:
2186-
raise SQLMeshError(f"Expected bool | list, got {type(ready_intervals)} for signal")
2186+
raise SignalEvalError(f"Expected bool | list, got {type(ready_intervals)} for signal")
21872187

21882188
checked_intervals.extend((to_timestamp(start), to_timestamp(end)) for start, end in batch)
21892189

sqlmesh/utils/errors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ class LinterError(SQLMeshError):
180180
pass
181181

182182

183+
class SignalEvalError(SQLMeshError):
184+
"""Errors when evaluating a signal that is because of a user mistake and not a SQLMesh bug."""
185+
186+
pass
187+
188+
183189
def raise_config_error(
184190
msg: str,
185191
location: t.Optional[str | Path] = None,

tests/core/test_snapshot.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
)
6464
from sqlmesh.utils import AttributeDict
6565
from sqlmesh.utils.date import DatetimeRanges, to_date, to_datetime, to_timestamp
66-
from sqlmesh.utils.errors import SQLMeshError
66+
from sqlmesh.utils.errors import SQLMeshError, SignalEvalError
6767
from sqlmesh.utils.jinja import JinjaMacroRegistry, MacroInfo
6868
from sqlmesh.core.console import get_console
6969

@@ -2571,6 +2571,15 @@ def assert_check_intervals(
25712571
[[(0, 1)], [(3, 4)]],
25722572
[(0, 1), (3, 4)],
25732573
)
2574+
with pytest.raises(SignalEvalError) as excinfo:
2575+
_check_ready_intervals(
2576+
lambda _: (_ for _ in ()).throw(MemoryError("Some exception")),
2577+
[(0, 1), (1, 2)],
2578+
mocker.Mock(),
2579+
)
2580+
2581+
assert isinstance(excinfo.value.__cause__, MemoryError)
2582+
assert str(excinfo.value.__cause__) == "Some exception"
25742583

25752584

25762585
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)