Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poor error handling in qemu_img helper #79

Open
nirs opened this issue May 30, 2022 · 0 comments
Open

Poor error handling in qemu_img helper #79

nirs opened this issue May 30, 2022 · 0 comments
Labels
enhancement Enhancing the system by adding new feature or improving performance or reliability good first issue Good issue for a new contributor

Comments

@nirs
Copy link
Member

nirs commented May 30, 2022

This module started as a testing helper, and fort his purpose is fine. But now it is used in
user visible context (e.g. client.upload, clinet.checksum) and it needs more robust error
handling.

One example is running client.checksum() with missing file:

$ examples/checksum no-such-file.qcow2
qemu-img: Could not open 'no-such-file.qcow2': Could not open 'no-such-file.qcow2': No such file or directory
Traceback (most recent call last):
  File "/home/nsoffer/src/ovirt-imageio/examples/checksum", line 17, in <module>
    res = client.checksum(path, algorithm="sha256")
  File "/usr/lib64/python3.10/site-packages/ovirt_imageio/client/_api.py", line 245, in checksum
    image_info = info(filename, member=member)
  File "/usr/lib64/python3.10/site-packages/ovirt_imageio/client/_api.py", line 205, in info
    return qemu_img.info(filename)
  File "/usr/lib64/python3.10/site-packages/ovirt_imageio/_internal/qemu_img.py", line 61, in info
    out = subprocess.check_output(cmd)
  File "/usr/lib64/python3.10/subprocess.py", line 420, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib64/python3.10/subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['qemu-img', 'info', '--output', 'json', 'no-such-file.qcow2']' returned non-zero exit status 1.

We get a good error from qemu-img written to stderr, but the traceback is not helpful.

Fix:

  • Capture stderr when running commands
  • Include stderr in the traceback (subprocess.CalledProcessError may already do the right thing)
@nirs nirs added enhancement Enhancing the system by adding new feature or improving performance or reliability good first issue Good issue for a new contributor labels May 30, 2022
@nirs nirs added this to the ovirt-4.5.1 milestone May 30, 2022
@nirs nirs modified the milestones: ovirt-4.5.1, ovirt-4.5.2 Jun 13, 2022
@nirs nirs modified the milestones: ovirt-4.5.2, ovirt-4.5.3 Jul 26, 2022
@aesteve-rh aesteve-rh changed the title Poor error handling in qem_img helper Poor error handling in qemu_img helper Aug 11, 2022
@sandrobonazzola sandrobonazzola removed this from the ovirt-4.5.4 milestone Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancing the system by adding new feature or improving performance or reliability good first issue Good issue for a new contributor
Projects
None yet
Development

No branches or pull requests

2 participants