From 61d54547379e292a0a7a43aef6a4cc279c937c6c Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 2 Jul 2018 06:06:11 +0200 Subject: [PATCH] Catch the raised exception so we can report failure (#42072) Avoid the _undefined name_ and mirror lines 389 and 459 by catching the raised exception in the variable __exc__ 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/module_utils/network/iosxr/iosxr.py:414:42: F821 undefined name 'exc' module.fail_json(msg=to_text(exc)) ^ ``` --- lib/ansible/module_utils/network/iosxr/iosxr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/network/iosxr/iosxr.py b/lib/ansible/module_utils/network/iosxr/iosxr.py index 2d8cd092c5..6889e86eea 100644 --- a/lib/ansible/module_utils/network/iosxr/iosxr.py +++ b/lib/ansible/module_utils/network/iosxr/iosxr.py @@ -410,7 +410,7 @@ def load_config(module, command_filter, commit=False, replace=False, try: conn.edit_config(cmd_filter) - except ConnectionError: + except ConnectionError as exc: module.fail_json(msg=to_text(exc)) if module._diff: