mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-04 07:51:50 +00:00
Use raise from in plugins (#11095)
* Use raise from. * Add changelog fragment.
This commit is contained in:
parent
1a82e93c6d
commit
2b4333a033
46 changed files with 218 additions and 165 deletions
|
|
@ -129,7 +129,7 @@ class Connection(ConnectionBase):
|
|||
try:
|
||||
self.chroot_cmd = get_bin_path(self.get_option("chroot_exe"))
|
||||
except ValueError as e:
|
||||
raise AnsibleError(str(e))
|
||||
raise AnsibleError(str(e)) from e
|
||||
|
||||
super()._connect()
|
||||
if not self._connected:
|
||||
|
|
@ -191,17 +191,17 @@ class Connection(ConnectionBase):
|
|||
count = ""
|
||||
try:
|
||||
p = self._buffered_exec_command(f"dd of={out_path} bs={BUFSIZE}{count}", stdin=in_file)
|
||||
except OSError:
|
||||
raise AnsibleError("chroot connection requires dd command in the chroot")
|
||||
except OSError as e:
|
||||
raise AnsibleError("chroot connection requires dd command in the chroot") from e
|
||||
try:
|
||||
stdout, stderr = p.communicate()
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
raise AnsibleError(f"failed to transfer file {in_path} to {out_path}")
|
||||
raise AnsibleError(f"failed to transfer file {in_path} to {out_path}") from e
|
||||
if p.returncode != 0:
|
||||
raise AnsibleError(f"failed to transfer file {in_path} to {out_path}:\n{stdout}\n{stderr}")
|
||||
except IOError:
|
||||
raise AnsibleError(f"file or module does not exist at: {in_path}")
|
||||
except IOError as e:
|
||||
raise AnsibleError(f"file or module does not exist at: {in_path}") from e
|
||||
|
||||
def fetch_file(self, in_path, out_path):
|
||||
"""fetch a file from chroot to local"""
|
||||
|
|
@ -211,8 +211,8 @@ class Connection(ConnectionBase):
|
|||
in_path = shlex_quote(self._prefix_login_path(in_path))
|
||||
try:
|
||||
p = self._buffered_exec_command(f"dd if={in_path} bs={BUFSIZE}")
|
||||
except OSError:
|
||||
raise AnsibleError("chroot connection requires dd command in the chroot")
|
||||
except OSError as e:
|
||||
raise AnsibleError("chroot connection requires dd command in the chroot") from e
|
||||
|
||||
with open(to_bytes(out_path, errors="surrogate_or_strict"), "wb+") as out_file:
|
||||
try:
|
||||
|
|
@ -220,9 +220,9 @@ class Connection(ConnectionBase):
|
|||
while chunk:
|
||||
out_file.write(chunk)
|
||||
chunk = p.stdout.read(BUFSIZE)
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
raise AnsibleError(f"failed to transfer file {in_path} to {out_path}")
|
||||
raise AnsibleError(f"failed to transfer file {in_path} to {out_path}") from e
|
||||
stdout, stderr = p.communicate()
|
||||
if p.returncode != 0:
|
||||
raise AnsibleError(f"failed to transfer file {in_path} to {out_path}:\n{stdout}\n{stderr}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue