Commit 194ef32 1 parent 6148f07 commit 194ef32 Copy full SHA for 194ef32
File tree 2 files changed +49
-1
lines changed
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):
655
655
656
656
def get_error_message (exc_value ):
657
657
# type: (Optional[BaseException]) -> str
658
- return (
658
+ value = (
659
659
getattr (exc_value , "message" , "" )
660
660
or getattr (exc_value , "detail" , "" )
661
661
or safe_str (exc_value )
662
662
)
663
+ notes = getattr (exc_value , "__notes__" , [])
664
+ if notes :
665
+ value = "\n " .join ([value ] + [safe_str (note ) for note in notes ])
666
+ return value
663
667
664
668
665
669
def 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):
778
778
with patch_start_tracing_child () as fake_start_child :
779
779
assert instance_or_class .class_ (1 ) == (TracingTestClass , 1 )
780
780
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