File tree 2 files changed +55
-2
lines changed
2 files changed +55
-2
lines changed Original file line number Diff line number Diff line change @@ -713,11 +713,21 @@ def get_errno(exc_value):
713
713
714
714
def get_error_message (exc_value ):
715
715
# type: (Optional[BaseException]) -> str
716
- return (
716
+ message = (
717
717
getattr (exc_value , "message" , "" )
718
718
or getattr (exc_value , "detail" , "" )
719
719
or safe_str (exc_value )
720
- )
720
+ ) # type: str
721
+
722
+ # __notes__ should be a list of strings when notes are added
723
+ # via add_note, but can be anything else if __notes__ is set
724
+ # directly. We only support strings in __notes__, since that
725
+ # is the correct use.
726
+ notes = getattr (exc_value , "__notes__" , None ) # type: object
727
+ if isinstance (notes , list ) and len (notes ) > 0 :
728
+ message += "\n " + "\n " .join (note for note in notes if isinstance (note , str ))
729
+
730
+ return message
721
731
722
732
723
733
def single_exception_from_error_tuple (
Original file line number Diff line number Diff line change @@ -999,3 +999,46 @@ 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
+ e .add_note ("another note" )
1012
+ raise e
1013
+ except Exception :
1014
+ capture_exception ()
1015
+
1016
+ (event ,) = events
1017
+
1018
+ assert event ["exception" ]["values" ][0 ]["value" ] == "aha!\n Test 123\n another note"
1019
+
1020
+
1021
+ @pytest .mark .skipif (sys .version_info < (3 , 11 ), reason = "add_note() not supported" )
1022
+ def test_notes_safe_str (sentry_init , capture_events ):
1023
+ class Note2 :
1024
+ def __repr__ (self ):
1025
+ raise TypeError
1026
+
1027
+ def __str__ (self ):
1028
+ raise TypeError
1029
+
1030
+ sentry_init ()
1031
+ events = capture_events ()
1032
+ try :
1033
+ e = ValueError ("aha!" )
1034
+ e .add_note ("note 1" )
1035
+ e .__notes__ .append (Note2 ()) # type: ignore
1036
+ e .add_note ("note 3" )
1037
+ e .__notes__ .append (2 ) # type: ignore
1038
+ raise e
1039
+ except Exception :
1040
+ capture_exception ()
1041
+
1042
+ (event ,) = events
1043
+
1044
+ assert event ["exception" ]["values" ][0 ]["value" ] == "aha!\n note 1\n note 3"
You can’t perform that action at this time.
0 commit comments