[Spice-devel] [PATCH spice-gtk 13/14] usb: do not return GError on programmer pre-condition checks

Jonathon Jongsma jjongsma at redhat.com
Wed Apr 23 14:43:03 PDT 2014



----- Original Message -----
> From: "Marc-André Lureau" <marcandre.lureau at gmail.com>
> To: spice-devel at freedesktop.org
> Sent: Wednesday, April 23, 2014 1:09:18 PM
> Subject: [Spice-devel] [PATCH spice-gtk 13/14] usb: do not return GError on	programmer pre-condition checks
> 
> Use regular g_warn/g_return precondition checks.
> 
> Do not fail on errors that can be ignored, but warn instead.
> ---
>  gtk/usb-device-manager.c | 13 ++-----------
>  1 file changed, 2 insertions(+), 11 deletions(-)
> 
> diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
> index 81e3c80..ec19564 100644
> --- a/gtk/usb-device-manager.c
> +++ b/gtk/usb-device-manager.c
> @@ -244,20 +244,11 @@ static gboolean
> spice_usb_device_manager_initable_init(GInitable  *initable,
>      g_return_val_if_fail(SPICE_IS_USB_DEVICE_MANAGER(initable), FALSE);
>      g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
>  
> -    if (cancellable != NULL) {
> -        g_set_error_literal(err, SPICE_CLIENT_ERROR,
> SPICE_CLIENT_ERROR_FAILED,
> -                            "Cancellable initialization not supported");
> -        return FALSE;
> -    }
> -
>      self = SPICE_USB_DEVICE_MANAGER(initable);
>      priv = self->priv;
>  
> -    if (!priv->session) {
> -        g_set_error_literal(err, SPICE_CLIENT_ERROR,
> SPICE_CLIENT_ERROR_FAILED,
> -                "SpiceUsbDeviceManager constructed without a session");
> -        return FALSE;
> -    }
> +    g_warn_if_fail(cancellable == NULL);
> +    g_return_val_if_fail(priv->session, FALSE);


Why return FALSE without setting error?  Doesn't that violate the contract for initable? From the docs:

  Returns: TRUE if successful. If an error has occurred, this function will return FALSE and set error appropriately if present.


>  
>  #ifdef USE_USBREDIR
>  
> --
> 1.8.5.3
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
> 


More information about the Spice-devel mailing list