From 10fd717a4460fc23b5a9c97e4bc99126fa868e26 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 2 Nov 2015 22:17:13 -0500 Subject: [PATCH] narrow the scope of import error and make sure non - aliases to ansible get their own error --- bin/ansible | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/ansible b/bin/ansible index 7420c2cc300..60d2bf42cbb 100755 --- a/bin/ansible +++ b/bin/ansible @@ -71,11 +71,15 @@ if __name__ == '__main__': mycli = getattr(__import__("ansible.cli.%s" % sub, fromlist=[myclass]), myclass) elif me == 'ansible': from ansible.cli.adhoc import AdHocCLI as mycli + else: + raise AnsibleError("Unknown Ansible alias: %s" % me) + except ImportError as e: + if e.message.endswith(' %s' % sub): + raise AnsibleError("Ansible sub-program not implemented: %s" % me) + else: + raise - cli = mycli(sys.argv, display=display) - except (ImportError,NameError): - raise AnsibleError("Ansible sub-program not implemented: %s" % me) - + cli = mycli(sys.argv, display=display) cli.parse() sys.exit(cli.run())