Skip to content

Commit

Permalink
Include error exception in AnsibleError
Browse files Browse the repository at this point in the history
- Use to_native instead of str

Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde authored and bcoca committed May 23, 2017
1 parent cce133b commit f9b836a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/ansible/plugins/connection/paramiko_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from ansible.module_utils.six.moves import input
from ansible.plugins.connection import ConnectionBase
from ansible.utils.path import makedirs_safe
from ansible.module_utils._text import to_bytes
from ansible.module_utils._text import to_bytes, to_native

try:
from __main__ import display
Expand Down Expand Up @@ -376,7 +376,7 @@ def fetch_file(self, in_path, out_path):
try:
self.sftp = self._connect_sftp()
except Exception as e:
raise AnsibleError("failed to open a SFTP connection (%s)", e)
raise AnsibleError("failed to open a SFTP connection (%s)" % to_native(e))

try:
self.sftp.get(to_bytes(in_path, errors='surrogate_or_strict'), to_bytes(out_path, errors='surrogate_or_strict'))
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/plugins/connection/zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, play_context, new_stdin, *args, **kwargs):
def _search_executable(executable):
cmd = distutils.spawn.find_executable(executable)
if not cmd:
raise AnsibleError("%s command not found in PATH") % executable
raise AnsibleError("%s command not found in PATH" % executable)
return cmd

def list_zones(self):
Expand Down
9 changes: 5 additions & 4 deletions lib/ansible/plugins/lookup/dig.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase
from ansible.module_utils._text import to_native
import socket

try:
Expand Down Expand Up @@ -146,7 +147,7 @@ def run(self, terms, variables=None, **kwargs):
nsaddr = dns.resolver.query(ns)[0].address
nameservers.append(nsaddr)
except Exception as e:
raise AnsibleError("dns lookup NS: ", str(e))
raise AnsibleError("dns lookup NS: %s" % to_native(e))
myres.nameservers = nameservers
continue
if '=' in t:
Expand All @@ -163,7 +164,7 @@ def run(self, terms, variables=None, **kwargs):
try:
rdclass = dns.rdataclass.from_text(arg)
except Exception as e:
raise errors.AnsibleError("dns lookup illegal CLASS: ", str(e))
raise AnsibleError("dns lookup illegal CLASS: %s" % to_native(e))

continue

Expand All @@ -186,7 +187,7 @@ def run(self, terms, variables=None, **kwargs):
except dns.exception.SyntaxError:
pass
except Exception as e:
raise AnsibleError("dns.reversename unhandled exception", str(e))
raise AnsibleError("dns.reversename unhandled exception %s" % to_native(e))

try:
answers = myres.query(domain, qtype, rdclass=rdclass)
Expand Down Expand Up @@ -216,6 +217,6 @@ def run(self, terms, variables=None, **kwargs):
except dns.resolver.Timeout:
ret.append('')
except dns.exception.DNSException as e:
raise AnsibleError("dns.resolver unhandled exception", e)
raise AnsibleError("dns.resolver unhandled exception %s" % to_native(e))

return ret
3 changes: 2 additions & 1 deletion lib/ansible/plugins/lookup/dnstxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase
from ansible.module_utils._text import to_native

# ==============================================================
# DNSTXT: DNS TXT records
Expand Down Expand Up @@ -57,7 +58,7 @@ def run(self, terms, variables=None, **kwargs):
except dns.resolver.Timeout:
string = ''
except DNSException as e:
raise AnsibleError("dns.resolver unhandled exception", e)
raise AnsibleError("dns.resolver unhandled exception %s" % to_native(e))

ret.append(''.join(string))

Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/plugins/lookup/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def generate_sequence(self):
yield formatted
except (ValueError, TypeError):
raise AnsibleError(
"problem formatting %r with %r" % self.format
"problem formatting %r with %r" % (i, self.format)
)

def run(self, terms, variables, **kwargs):
Expand Down

0 comments on commit f9b836a

Please sign in to comment.