11import random
22import os
33import hawkcatcher
4+ from faker import Faker
5+
6+ fake = Faker ()
47
58def divide_by_zero ():
69 a = random .randint (1 , 100 )
@@ -32,6 +35,12 @@ def value_error():
3235 invalid_strings = ['abc' , 'NaN' , 'invalid' ]
3336 return int (random .choice (invalid_strings ))
3437
38+ def random_exception ():
39+ title = fake .sentence (nb_words = 6 )
40+ exception_types = [ValueError , KeyError , IndexError , TypeError , AssertionError , ZeroDivisionError ]
41+ selected_exception = random .choice (exception_types )
42+ raise selected_exception (f"Error: { title } " )
43+
3544exceptions = [
3645 divide_by_zero , trigger_manual_exception ,
3746 invalid_operation , index_out_of_range , key_error ,
@@ -46,5 +55,14 @@ def value_error():
4655 func = random .choice (exceptions )
4756 func ()
4857 except Exception as e :
49- random_ip = f'{ random .randint (1 , 255 )} .{ random .randint (1 , 255 )} .{ random .randint (1 , 255 )} .{ random .randint (1 , 255 )} '
50- hawkcatcher .send (e , {'ip' : random_ip , 'value' : random .randint (1 , 100 )})
58+ random_username = fake .user_name ()
59+ random_email = fake .email ()
60+ hawkcatcher .send (e , {'username' : random_username , 'value' : random_email })
61+
62+ for _ in range (2 ):
63+ try :
64+ random_exception ()
65+ except Exception as e :
66+ random_username = fake .user_name ()
67+ random_email = fake .email ()
68+ hawkcatcher .send (e , {'username' : random_username , 'value' : random_email })
0 commit comments