Skip to content

Commit ac21607

Browse files
Ignore non-str notes
1 parent 9a04d67 commit ac21607

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

sentry_sdk/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,10 +717,12 @@ def get_error_message(exc_value):
717717
getattr(exc_value, "message", "")
718718
or getattr(exc_value, "detail", "")
719719
or safe_str(exc_value)
720-
)
721-
notes = getattr(exc_value, "__notes__", [])
722-
if notes:
723-
value = "\n".join([value] + [safe_str(note) for note in notes])
720+
) # type: str
721+
722+
notes = getattr(exc_value, "__notes__", None) # type: object
723+
if isinstance(notes, list) and len(notes) > 0:
724+
value += "\n" + "\n".join(note for note in notes if isinstance(note, str))
725+
724726
return value
725727

726728

tests/test_basics.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,13 +1008,14 @@ def test_notes(sentry_init, capture_events):
10081008
try:
10091009
e = ValueError("aha!")
10101010
e.add_note("Test 123")
1011+
e.add_note("another note")
10111012
raise e
10121013
except Exception:
10131014
capture_exception()
10141015

10151016
(event,) = events
10161017

1017-
assert event["exception"]["values"][0]["value"] == "aha!\nTest 123"
1018+
assert event["exception"]["values"][0]["value"] == "aha!\nTest 123\nanother note"
10181019

10191020

10201021
@pytest.mark.skipif(sys.version_info < (3, 11), reason="add_note() not supported")
@@ -1033,13 +1034,11 @@ def __str__(self):
10331034
e.add_note("note 1")
10341035
e.__notes__.append(Note2()) # type: ignore
10351036
e.add_note("note 3")
1037+
e.__notes__.append(2) # type: ignore
10361038
raise e
10371039
except Exception:
10381040
capture_exception()
10391041

10401042
(event,) = events
10411043

1042-
assert (
1043-
event["exception"]["values"][0]["value"]
1044-
== "aha!\nnote 1\n<broken repr>\nnote 3"
1045-
)
1044+
assert event["exception"]["values"][0]["value"] == "aha!\nnote 1\nnote 3"

0 commit comments

Comments
 (0)