Skip to content

Commit 5f1c10a

Browse files
committed
Fix Exception.capture error handling
Ref #599 `sys.exc_info()` returns `(None, None, None)` if there is no active exception. Still fail hard and fast, but more clearly.
1 parent 7894d26 commit 5f1c10a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

elasticapm/events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ def capture(client, exc_info=None, **kwargs):
8686
new_exc_info = True
8787
exc_info = sys.exc_info()
8888

89-
if not exc_info:
90-
raise ValueError("No exception found")
89+
if exc_info == (None, None, None):
90+
raise ValueError("No exception found: capture_exception requires an active exception.")
9191

9292
try:
9393
exc_type, exc_value, exc_traceback = exc_info

tests/events/tests.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232

3333
from __future__ import absolute_import
3434

35+
import pytest
3536
from mock import Mock
3637

37-
from elasticapm.events import Message
38+
from elasticapm.events import Exception, Message
3839

3940

4041
def test_event_to_string():
@@ -46,3 +47,8 @@ def test_event_to_string():
4647
data = {"log": {"message": unformatted_message % (1, 2), "param_message": unformatted_message}}
4748

4849
assert message.to_string(client, data) == formatted_message
50+
51+
52+
def test_capture_exception_no_exception(elasticapm_client):
53+
with pytest.raises(ValueError):
54+
Exception.capture(elasticapm_client)

0 commit comments

Comments
 (0)