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 @@ -655,11 +655,15 @@ def get_errno(exc_value):
655655
656656def get_error_message (exc_value ):
657657 # type: (Optional[BaseException]) -> str
658- return (
658+ value = (
659659 getattr (exc_value , "message" , "" )
660660 or getattr (exc_value , "detail" , "" )
661661 or safe_str (exc_value )
662662 )
663+ notes = getattr (exc_value , "__notes__" , [])
664+ if notes :
665+ value = "\n " .join ([value ] + [safe_str (note ) for note in notes ])
666+ return value
663667
664668
665669def single_exception_from_error_tuple (
Original file line number Diff line number Diff line change @@ -778,3 +778,47 @@ def test_classmethod_tracing(sentry_init):
778778 with patch_start_tracing_child () as fake_start_child :
779779 assert instance_or_class .class_ (1 ) == (TracingTestClass , 1 )
780780 assert fake_start_child .call_count == 1
781+
782+
783+ @pytest .mark .skipif (sys .version_info < (3 , 11 ), reason = "add_note() not supported" )
784+ def test_notes (sentry_init , capture_events ):
785+ sentry_init ()
786+ events = capture_events ()
787+ try :
788+ e = ValueError ("aha!" )
789+ e .add_note ("Test 123" )
790+ raise e
791+ except Exception :
792+ capture_exception ()
793+
794+ (event ,) = events
795+
796+ assert event ["exception" ]["values" ][0 ]["value" ] == "aha!\n Test 123"
797+
798+
799+ @pytest .mark .skipif (sys .version_info < (3 , 11 ), reason = "add_note() not supported" )
800+ def test_notes_safe_str (sentry_init , capture_events ):
801+ class Note2 :
802+ def __repr__ (self ):
803+ raise TypeError
804+
805+ def __str__ (self ):
806+ raise TypeError
807+
808+ sentry_init ()
809+ events = capture_events ()
810+ try :
811+ e = ValueError ("aha!" )
812+ e .add_note ("note 1" )
813+ e .__notes__ .append (Note2 ()) # type: ignore
814+ e .add_note ("note 3" )
815+ raise e
816+ except Exception :
817+ capture_exception ()
818+
819+ (event ,) = events
820+
821+ assert (
822+ event ["exception" ]["values" ][0 ]["value" ]
823+ == "aha!\n note 1\n <broken repr>\n note 3"
824+ )
You can’t perform that action at this time.
0 commit comments