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):
713
713
714
714
def get_error_message (exc_value ):
715
715
# type: (Optional[BaseException]) -> str
716
- return (
716
+ value = (
717
717
getattr (exc_value , "message" , "" )
718
718
or getattr (exc_value , "detail" , "" )
719
719
or safe_str (exc_value )
720
720
)
721
+ notes = getattr (exc_value , "__notes__" , [])
722
+ if notes :
723
+ value = "\n " .join ([value ] + [safe_str (note ) for note in notes ])
724
+ return value
721
725
722
726
723
727
def 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():
999
999
def test_hub_main_deprecation_warnings ():
1000
1000
with pytest .warns (sentry_sdk .hub .SentryHubDeprecationWarning ):
1001
1001
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