File tree Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -713,11 +713,15 @@ def get_errno(exc_value):
713713
714714def get_error_message (exc_value ):
715715 # type: (Optional[BaseException]) -> str
716- return (
716+ value = (
717717 getattr (exc_value , "message" , "" )
718718 or getattr (exc_value , "detail" , "" )
719719 or safe_str (exc_value )
720720 )
721+ notes = getattr (exc_value , "__notes__" , [])
722+ if notes :
723+ value = "\n " .join ([value ] + [safe_str (note ) for note in notes ])
724+ return value
721725
722726
723727def single_exception_from_error_tuple (
Original file line number Diff line number Diff line change @@ -999,3 +999,47 @@ def test_hub_current_deprecation_warning():
999999def test_hub_main_deprecation_warnings ():
10001000 with pytest .warns (sentry_sdk .hub .SentryHubDeprecationWarning ):
10011001 Hub .main
1002+
1003+
1004+ @pytest .mark .skipif (sys .version_info < (3 , 11 ), reason = "add_note() not supported" )
1005+ def test_notes (sentry_init , capture_events ):
1006+ sentry_init ()
1007+ events = capture_events ()
1008+ try :
1009+ e = ValueError ("aha!" )
1010+ e .add_note ("Test 123" )
1011+ raise e
1012+ except Exception :
1013+ capture_exception ()
1014+
1015+ (event ,) = events
1016+
1017+ assert event ["exception" ]["values" ][0 ]["value" ] == "aha!\n Test 123"
1018+
1019+
1020+ @pytest .mark .skipif (sys .version_info < (3 , 11 ), reason = "add_note() not supported" )
1021+ def test_notes_safe_str (sentry_init , capture_events ):
1022+ class Note2 :
1023+ def __repr__ (self ):
1024+ raise TypeError
1025+
1026+ def __str__ (self ):
1027+ raise TypeError
1028+
1029+ sentry_init ()
1030+ events = capture_events ()
1031+ try :
1032+ e = ValueError ("aha!" )
1033+ e .add_note ("note 1" )
1034+ e .__notes__ .append (Note2 ()) # type: ignore
1035+ e .add_note ("note 3" )
1036+ raise e
1037+ except Exception :
1038+ capture_exception ()
1039+
1040+ (event ,) = events
1041+
1042+ assert (
1043+ event ["exception" ]["values" ][0 ]["value" ]
1044+ == "aha!\n note 1\n <broken repr>\n note 3"
1045+ )
You can’t perform that action at this time.
0 commit comments