From b29af922eb4489a1661b7b6df2d8c5695a2d8901 Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: Wed, 29 Jul 2020 15:38:51 -0600 Subject: [PATCH] jira: cast error messages to strings (#707) Sometimes Jira returns dicts as "errors" instead of simple strings. For example, when a user specifies a field that cannot be set, Jira returns a dict with the field name as a key and the error message as the value. In the rare case that we have both a "errorMessages" list and an "errors" dict, when we combine those values later with join(), Python raises a TypeError. Transform each individual error message into a string, and then join() the list of strings. --- changelogs/fragments/707-jira-error-handling.yaml | 2 ++ plugins/modules/web_infrastructure/jira.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/707-jira-error-handling.yaml diff --git a/changelogs/fragments/707-jira-error-handling.yaml b/changelogs/fragments/707-jira-error-handling.yaml new file mode 100644 index 0000000000..23f4ac2629 --- /dev/null +++ b/changelogs/fragments/707-jira-error-handling.yaml @@ -0,0 +1,2 @@ +bugfixes: +- jira - improve error message handling with multiple errors (https://github.com/ansible-collections/community.general/pull/707). diff --git a/plugins/modules/web_infrastructure/jira.py b/plugins/modules/web_infrastructure/jira.py index 9936439d52..e06a5cac77 100644 --- a/plugins/modules/web_infrastructure/jira.py +++ b/plugins/modules/web_infrastructure/jira.py @@ -314,9 +314,9 @@ def request(url, user, passwd, timeout, data=None, method=None): msg = [] for key in ('errorMessages', 'errors'): if error.get(key): - msg.append(error[key]) + msg.append(to_native(error[key])) if msg: - module.fail_json(msg=to_native(', '.join(msg))) + module.fail_json(msg=', '.join(msg)) else: module.fail_json(msg=to_native(error)) else: