Skip to content

Commit

Permalink
ansible-galaxy role info - fix unhandled AttributeError
Browse files Browse the repository at this point in the history
* catch GalaxyError instead of its base class to ensure it will have a http_error attribute
  • Loading branch information
s-hertel authored Mar 9, 2023
1 parent cb2180e commit 6165dfe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/a-g-role-fix-catching-exception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- ansible-galaxy role info - fix unhandled AttributeError by catching the correct exception.
4 changes: 2 additions & 2 deletions lib/ansible/cli/galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
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,
Expand Down Expand Up @@ -1220,7 +1220,7 @@ def execute_info(self):
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
Expand Down

0 comments on commit 6165dfe

Please sign in to comment.