[PR #11095/2b4333a0 backport][stable-12] Use raise from in plugins (#11129)

Use raise from in plugins (#11095)

* Use raise from.

* Add changelog fragment.

(cherry picked from commit 2b4333a033)

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot]
2025-11-12 21:00:39 +01:00
committed by GitHub
parent cddb570e0e
commit cc93dab0fd
46 changed files with 218 additions and 165 deletions

View File

@@ -173,9 +173,9 @@ class Connection(ConnectionBase):
raise errors.AnsibleFileNotFound(msg)
try:
src_file = open(in_path, "rb")
except IOError:
except IOError as e:
traceback.print_exc()
raise errors.AnsibleError(f"failed to open input file to {in_path}")
raise errors.AnsibleError(f"failed to open input file to {in_path}") from e
try:
def write_file(args):
@@ -184,10 +184,10 @@ class Connection(ConnectionBase):
try:
self.container.attach_wait(write_file, None)
except IOError:
except IOError as e:
traceback.print_exc()
msg = f"failed to transfer file to {out_path}"
raise errors.AnsibleError(msg)
raise errors.AnsibleError(msg) from e
finally:
src_file.close()
@@ -200,10 +200,10 @@ class Connection(ConnectionBase):
try:
dst_file = open(out_path, "wb")
except IOError:
except IOError as e:
traceback.print_exc()
msg = f"failed to open output file {out_path}"
raise errors.AnsibleError(msg)
raise errors.AnsibleError(msg) from e
try:
def write_file(args):
@@ -217,10 +217,10 @@ class Connection(ConnectionBase):
try:
self.container.attach_wait(write_file, None)
except IOError:
except IOError as e:
traceback.print_exc()
msg = f"failed to transfer file from {in_path} to {out_path}"
raise errors.AnsibleError(msg)
raise errors.AnsibleError(msg) from e
finally:
dst_file.close()