@@ -58,6 +58,43 @@ def test_notice_error_no_exc_info():
5858 notice_error ()
5959
6060
61+ @validate_transaction_errors (errors = [(_runtime_error_name , "one" )])
62+ @background_task ()
63+ def test_notice_error_exception_instance ():
64+ """Test that notice_error works when passed an exception object directly"""
65+ try :
66+ raise RuntimeError ("one" )
67+ except RuntimeError as e :
68+ exc = e # Reassign name to ensure scope isn't lost
69+
70+ # Call notice_error outside of try/except block to ensure it's not pulling from sys.exc_info()
71+ notice_error (exc )
72+
73+
74+ @validate_transaction_errors (errors = [(_runtime_error_name , "one" ), (_type_error_name , "two" )])
75+ @background_task ()
76+ def test_notice_error_exception_instance_multiple_exceptions ():
77+ """Test that notice_error reports the passed exception object even when a different exception is active."""
78+ try :
79+ raise RuntimeError ("one" )
80+ except RuntimeError as e :
81+ exc1 = e # Reassign name to ensure scope isn't lost
82+
83+ try :
84+ raise TypeError ("two" )
85+ except TypeError as exc2 :
86+ notice_error (exc1 )
87+ notice_error (exc2 )
88+
89+
90+ @validate_transaction_error_event_count (0 )
91+ @background_task ()
92+ def test_notice_error_exception_instance_no_traceback ():
93+ """Test that notice_error does not report an exception if it has not been raised as it has no __traceback__"""
94+ exc = RuntimeError ("one" )
95+ notice_error (exc ) # Try once with no active exception
96+
97+
6198@validate_transaction_errors (errors = [(_runtime_error_name , "one" )], required_params = [("key" , "value" )])
6299@background_task ()
63100def test_notice_error_custom_params ():
0 commit comments