Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8d30aec

Browse files
committed
improving the exception handling and couple other things
1 parent 0ac49b7 commit 8d30aec

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

‎python/chaos_lib.py‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
sys.path.insert(0, '/opt/python/.vendor')
55

6-
from ssm_cache import SSMParameter
6+
from ssm_cache import SSMParameter, InvalidParameterError
77
import time
88
import random
99
import json
@@ -22,12 +22,15 @@ def get_config():
2222
return -1
2323
else:
2424
return 0
25-
except Exception as e:
26-
print(e)
25+
except InvalidParameterError as e:
26+
print("{} does not exist in SSM".format(e))
27+
return 0
28+
except KeyError as e:
29+
print("{} is not a valid Key in the SSM configuration".format(e))
2730
return 0
2831

2932

30-
def delayit(method):
33+
def delayit(func):
3134
def latency(*args, **kw):
3235
delay = get_config()
3336
start = time.time()
@@ -40,14 +43,12 @@ def latency(*args, **kw):
4043
if random.random() > 0.5:
4144
# random sleep time between 1 and 10 seconds
4245
time.sleep(random.randint(1, 10))
43-
else:
44-
pass
4546

46-
result = method(*args, **kw)
47+
result = func(*args, **kw)
4748
end = time.time()
4849

4950
print('Added {1:.2f}ms to {0:s}'.format(
50-
method.__name__,
51+
func.__name__,
5152
(end - start) * 1000
5253
))
5354

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /