mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 20:01:25 -07:00
Do not use str() on exceptions (#46950)
This commit is contained in:
parent
2436aa1a4e
commit
a80c25cbd9
30 changed files with 76 additions and 66 deletions
|
@ -70,6 +70,7 @@ try:
|
|||
except ImportError:
|
||||
HAS_REQUESTS = False
|
||||
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
|
||||
|
@ -152,7 +153,7 @@ class CallbackModule(CallbackBase):
|
|||
verify=self.ssl_verify)
|
||||
r.raise_for_status()
|
||||
except requests.exceptions.RequestException as err:
|
||||
print(str(err))
|
||||
print(to_text(err))
|
||||
|
||||
def _build_log(self, data):
|
||||
logs = []
|
||||
|
@ -214,7 +215,7 @@ class CallbackModule(CallbackBase):
|
|||
verify=self.ssl_verify)
|
||||
r.raise_for_status()
|
||||
except requests.exceptions.RequestException as err:
|
||||
print(str(err))
|
||||
print(to_text(err))
|
||||
self.items[host] = []
|
||||
|
||||
def append_result(self, result):
|
||||
|
|
|
@ -24,6 +24,7 @@ import getpass
|
|||
from base64 import b64encode
|
||||
from datetime import datetime
|
||||
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
|
@ -259,4 +260,4 @@ class CallbackModule(CallbackBase):
|
|||
url_username=self.grafana_user, url_password=self.grafana_password,
|
||||
http_agent=self.http_agent, force_basic_auth=self.force_basic_auth)
|
||||
except Exception as e:
|
||||
self._display.error('Could not submit message to Grafana: %s' % str(e))
|
||||
self._display.error(u'Could not submit message to Grafana: %s' % to_text(e))
|
||||
|
|
|
@ -111,7 +111,7 @@ try:
|
|||
except ImportError:
|
||||
HAS_FLATDICT = False
|
||||
|
||||
from ansible.module_utils._text import to_bytes, to_text, to_native
|
||||
from ansible.module_utils._text import to_bytes, to_text
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
# Todo:
|
||||
|
@ -147,7 +147,7 @@ class PlainTextSocketAppender(object):
|
|||
self.open_connection()
|
||||
return
|
||||
except Exception as e:
|
||||
self._display.vvvv("Unable to connect to Logentries: %s" % str(e))
|
||||
self._display.vvvv(u"Unable to connect to Logentries: %s" % to_text(e))
|
||||
|
||||
root_delay *= 2
|
||||
if root_delay > self.MAX_DELAY:
|
||||
|
@ -247,7 +247,7 @@ class CallbackModule(CallbackBase):
|
|||
self.use_tls = self.get_option('use_tls')
|
||||
self.flatten = self.get_option('flatten')
|
||||
except KeyError as e:
|
||||
self._display.warning("Missing option for Logentries callback plugin: %s" % to_native(e))
|
||||
self._display.warning(u"Missing option for Logentries callback plugin: %s" % to_text(e))
|
||||
self.disabled = True
|
||||
|
||||
try:
|
||||
|
|
|
@ -53,6 +53,7 @@ try:
|
|||
except ImportError:
|
||||
cli = None
|
||||
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
|
@ -124,8 +125,8 @@ class CallbackModule(CallbackBase):
|
|||
response = open_url(self.webhook_url, data=data)
|
||||
return response.read()
|
||||
except Exception as e:
|
||||
self._display.warning('Could not submit message to Slack: %s' %
|
||||
str(e))
|
||||
self._display.warning(u'Could not submit message to Slack: %s' %
|
||||
to_text(e))
|
||||
|
||||
def v2_playbook_on_start(self, playbook):
|
||||
self.playbook_name = os.path.basename(playbook._file_name)
|
||||
|
|
|
@ -20,7 +20,7 @@ DOCUMENTATION = '''
|
|||
import os
|
||||
|
||||
from ansible.constants import TREE_DIR
|
||||
from ansible.module_utils._text import to_bytes
|
||||
from ansible.module_utils._text import to_bytes, to_text
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
from ansible.utils.path import makedirs_safe
|
||||
|
||||
|
@ -53,7 +53,7 @@ class CallbackModule(CallbackBase):
|
|||
with open(path, 'wb+') as fd:
|
||||
fd.write(buf)
|
||||
except (OSError, IOError) as e:
|
||||
self._display.warning("Unable to write to %s's file: %s" % (hostname, str(e)))
|
||||
self._display.warning(u"Unable to write to %s's file: %s" % (hostname, to_text(e)))
|
||||
|
||||
def result_to_tree(self, result):
|
||||
if self.tree:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue