From 28c9d93fe07b9f18a0c3e2f87559756edd5364a5 Mon Sep 17 00:00:00 2001 From: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> Date: Mon, 20 Mar 2023 12:54:57 -0400 Subject: ansible-galaxy role info - fix unhandled AttributeError (#80187) * catch GalaxyError instead of its base class to ensure it will have a http_error attribute (cherry picked from commit 6165dfea4040fdac9d73e9f415f3da9b0b8a3591) --- changelogs/fragments/a-g-role-fix-catching-exception.yml | 2 ++ lib/ansible/cli/galaxy.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/a-g-role-fix-catching-exception.yml diff --git a/changelogs/fragments/a-g-role-fix-catching-exception.yml b/changelogs/fragments/a-g-role-fix-catching-exception.yml new file mode 100644 index 0000000000..210cc57d4d --- /dev/null +++ b/changelogs/fragments/a-g-role-fix-catching-exception.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-galaxy role info - fix unhandled AttributeError by catching the correct exception. diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 3cb7fe2c0b..24727d32ba 100755 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -27,7 +27,7 @@ from ansible import context from ansible.cli.arguments import option_helpers as opt_help from ansible.errors import AnsibleError, AnsibleOptionsError from ansible.galaxy import Galaxy, get_collections_galaxy_meta_info -from ansible.galaxy.api import GalaxyAPI +from ansible.galaxy.api import GalaxyAPI, GalaxyError from ansible.galaxy.collection import ( build_collection, download_collections, @@ -1214,7 +1214,7 @@ class GalaxyCLI(CLI): remote_data = None try: remote_data = self.api.lookup_role_by_name(role, False) - except AnsibleError as e: + except GalaxyError as e: if e.http_code == 400 and 'Bad Request' in e.message: # Role does not exist in Ansible Galaxy data = u"- the role %s was not found" % role -- cgit v1.2.1