Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/memos/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ def wrapper(*args, **kwargs):
if fallback is not None and callable(fallback):
result = fallback(e, *args, **kwargs)
return result
else:
# Re-raise the exception if no fallback is provided
raise
finally:
elapsed_ms = (time.perf_counter() - start) * 1000.0

Expand Down
31 changes: 31 additions & 0 deletions tests/test_utils_timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,34 @@ def parens():

assert bare() == 1
assert parens() == 2

def test_exception_without_fallback_should_propagate(self, caplog):
"""Bug fix: exceptions should be re-raised when no fallback is provided."""

@timed_with_status
def failing_func():
raise ValueError("test exception")

with caplog.at_level(logging.INFO):
with pytest.raises(ValueError, match="test exception"):
failing_func()

# The exception should propagate AND the failure should be logged
logs = _collect_timer_with_status_logs(caplog)
assert len(logs) == 1
assert "status: FAILED" in logs[0]
assert "error_type: ValueError" in logs[0]

def test_exception_with_none_fallback_should_propagate(self, caplog):
"""Bug fix: explicit fallback=None should still re-raise exceptions."""

@timed_with_status(fallback=None)
def failing_func():
raise RuntimeError("explicit none")

with caplog.at_level(logging.INFO):
with pytest.raises(RuntimeError, match="explicit none"):
failing_func()

logs = _collect_timer_with_status_logs(caplog)
assert "status: FAILED" in logs[0]
Loading