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 @@ -688,11 +688,15 @@ def get_errno(exc_value):
688688
689689def get_error_message (exc_value ):
690690 # type: (Optional[BaseException]) -> str
691- return (
691+ value = (
692692 getattr (exc_value , "message" , "" )
693693 or getattr (exc_value , "detail" , "" )
694694 or safe_str (exc_value )
695695 )
696+ notes = getattr (exc_value , "__notes__" , [])
697+ if notes :
698+ value = "\n " .join ([value ] + [safe_str (note ) for note in notes ])
699+ return value
696700
697701
698702def single_exception_from_error_tuple (
Original file line number Diff line number Diff line change @@ -955,3 +955,47 @@ def test_hub_current_deprecation_warning():
955955def test_hub_main_deprecation_warnings ():
956956 with pytest .warns (sentry_sdk .hub .SentryHubDeprecationWarning ):
957957 Hub .main
958+
959+
960+ @pytest .mark .skipif (sys .version_info < (3 , 11 ), reason = "add_note() not supported" )
961+ def test_notes (sentry_init , capture_events ):
962+ sentry_init ()
963+ events = capture_events ()
964+ try :
965+ e = ValueError ("aha!" )
966+ e .add_note ("Test 123" )
967+ raise e
968+ except Exception :
969+ capture_exception ()
970+
971+ (event ,) = events
972+
973+ assert event ["exception" ]["values" ][0 ]["value" ] == "aha!\n Test 123"
974+
975+
976+ @pytest .mark .skipif (sys .version_info < (3 , 11 ), reason = "add_note() not supported" )
977+ def test_notes_safe_str (sentry_init , capture_events ):
978+ class Note2 :
979+ def __repr__ (self ):
980+ raise TypeError
981+
982+ def __str__ (self ):
983+ raise TypeError
984+
985+ sentry_init ()
986+ events = capture_events ()
987+ try :
988+ e = ValueError ("aha!" )
989+ e .add_note ("note 1" )
990+ e .__notes__ .append (Note2 ()) # type: ignore
991+ e .add_note ("note 3" )
992+ raise e
993+ except Exception :
994+ capture_exception ()
995+
996+ (event ,) = events
997+
998+ assert (
999+ event ["exception" ]["values" ][0 ]["value" ]
1000+ == "aha!\n note 1\n <broken repr>\n note 3"
1001+ )
You can’t perform that action at this time.
0 commit comments