[Libguestfs] [PATCH libnbd v3] python: Raise a custom exception containing error string and errno.
Eric Blake
eblake at redhat.com
Fri Jun 28 20:01:40 UTC 2019
On 6/28/19 1:27 PM, Richard W.M. Jones wrote:
> Previously errors caused a RuntimeException to be raised. This commit
> defines a custom exception (nbd.Error) which has two parameters, the
> required error string, and the optional errno (which may be 0 if
> unavailable).
>
> +static inline void
> +raise_exception ()
> +{
> + PyObject *args = PyTuple_New (2);
> +
> + PyTuple_SetItem (args, 0, PyUnicode_FromString (nbd_get_error ()));
> + PyTuple_SetItem (args, 1, PyLong_FromLong (nbd_get_errno ()));
These three lines could probably be compressed into:
Py_BuildValue("si", nbd_get_error(), nbd_get_errno ());
I'll look for other shortcuts like that while auditing for proper error
checking.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190628/9cead558/attachment.sig>
More information about the Libguestfs
mailing list