include traceback in exception handling (#22807)

pull/4420/head
Sloane Hertel 2017-03-23 14:08:02 -04:00 committed by Ryan Brown
parent 0bb3545333
commit 1ca4a42c0e
1 changed files with 7 additions and 4 deletions

View File

@ -142,7 +142,7 @@ else:
### Exception Handling ### Exception Handling
You should wrap any boto call in a try block. If an exception is thrown, it is up to you decide how to handle it You should wrap any boto call in a try block. If an exception is thrown, it is up to you decide how to handle it
but usually calling fail_json with the error message will suffice. but usually calling fail_json with the error or helpful message and traceback will suffice.
#### boto #### boto
@ -162,7 +162,8 @@ except ImportError:
try: try:
result = connection.aws_call() result = connection.aws_call()
except BotoServerError, e: except BotoServerError, e:
module.fail_json(msg=e.message) module.fail_json(msg="helpful message here", exception=traceback.format_exc(),
**camel_dict_to_snake_dict(e.message))
``` ```
#### boto3 #### boto3
@ -186,7 +187,8 @@ except ImportError:
try: try:
result = connection.aws_call() result = connection.aws_call()
except ClientError, e: except ClientError, e:
module.fail_json(msg=e.message, **camel_dict_to_snake_dict(e.response)) module.fail_json(msg=e.message, exception=traceback.format_ex(),
**camel_dict_to_snake_dict(e.response))
``` ```
If you need to perform an action based on the error boto3 returned, use the error code. If you need to perform an action based on the error boto3 returned, use the error code.
@ -199,7 +201,8 @@ except ClientError, e:
if e.response['Error']['Code'] == 'NoSuchEntity': if e.response['Error']['Code'] == 'NoSuchEntity':
return None return None
else: else:
module.fail_json(msg=e.message, **camel_dict_to_snake_dict(e.response)) module.fail_json(msg=e.message, exception=traceback.format_exc(),
**camel_dict_to_snake_dict(e.response))
``` ```
### Returning Values ### Returning Values