Skip to content

Commit 86dcf17

Browse files
committed
Add some randomness to demo events
1 parent 9765fb8 commit 86dcf17

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

example/fill_events.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import random
22
import os
33
import hawkcatcher
4+
from faker import Faker
5+
6+
fake = Faker()
47

58
def 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+
3544
exceptions = [
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})

example/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
hawkcatcher
1+
hawkcatcher
2+
faker

0 commit comments

Comments
 (0)