From 14bc625c2ce7602f861bff21fff992d8f2f36f87 Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 2 Jul 2018 14:45:36 +0200 Subject: [PATCH] Catch the raised exception so we can report failure (#42177) [AWS iam_policy] Avoid the _undefined name_ by catching the raised exception into the variable __e__ so it can be reported on the following line. flake8 testing of https://github.com/ansible/ansible on Python 3.6.3 $ __flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics__ ``` ./lib/ansible/modules/cloud/amazon/iam_policy.py:305:16: F821 undefined name 'e' if e.errno == 2: ^ ./lib/ansible/modules/cloud/misc/rhevm.py:594:24: F821 undefined name 'e' setMsg(str(e)) ^ ./lib/ansible/modules/files/archive.py:391:92: F821 undefined name 'e' module.fail_json(dest=dest, msg='Error deleting some source files: ' + str(e), files=errors) ^ 3 F821 undefined name 'e' 3 ``` --- lib/ansible/modules/cloud/amazon/iam_policy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/amazon/iam_policy.py b/lib/ansible/modules/cloud/amazon/iam_policy.py index 1b53790559..87f32c9838 100644 --- a/lib/ansible/modules/cloud/amazon/iam_policy.py +++ b/lib/ansible/modules/cloud/amazon/iam_policy.py @@ -301,7 +301,7 @@ def main(): with open(policy_document, 'r') as json_data: pdoc = json.dumps(json.load(json_data)) json_data.close() - except IOError: + except IOError as e: if e.errno == 2: module.fail_json( msg='policy_document {0:!r} does not exist'.format(policy_document))