[virt-tools-list] [virt-viewer: PATCH 2/4 v2] Improve authentication error messages

Jonathon Jongsma jjongsma at redhat.com
Thu Sep 25 18:24:58 UTC 2014


On Wed, 2014-09-24 at 13:49 +0200, Fabiano Fidêncio wrote:
> Adding a better error message to our default error message, based on the
> libvirt error. Also, the libvirt error is shown as debug.
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=1142742
> ---
> v2:
> - Add a special case with our own error message based on libvirt's error message
> - Add a g_debug() output with the libvirt's error message
> ---
>  src/virt-viewer.c | 37 +++++++++++++++++++++++++++++++++++--
>  1 file changed, 35 insertions(+), 2 deletions(-)
> 
> diff --git a/src/virt-viewer.c b/src/virt-viewer.c
> index 3d5a363..c6066c5 100644
> --- a/src/virt-viewer.c
> +++ b/src/virt-viewer.c
> @@ -669,6 +669,36 @@ virt_viewer_auth_libvirt_credentials(virConnectCredentialPtr cred,
>      return ret;
>  }
>  
> +static gchar *
> +virt_viewer_get_error_message_from_vir_error(VirtViewer *self,
> +                                             virErrorPtr error)
> +{
> +    VirtViewerPrivate *priv = self->priv;
> +    const gchar *error_details = NULL;
> +    gchar *detailed_error_message = NULL;
> +    gchar *error_message = g_strdup_printf(_("Unable to connect to libvirt with URI: %s."),
> +                                           priv->uri ? priv->uri : _("[none]"));
> +
> +    g_debug("Error: %s", error->message);


I'm not so sure whether simply *getting* the error message should have a
side-effect of printing a debug message, but I guess it's OK.

ACK


> +
> +    /* For now we are only treating authentication errors. */
> +    switch (error->code) {
> +        case VIR_ERR_AUTH_FAILED:
> +            error_details = _("Authentication failed.");
> +            break;
> +        default:
> +            break;
> +    }
> +
> +    if (error_details != NULL) {
> +        detailed_error_message = g_strdup_printf("%s\n%s", error_message, error_details);
> +        g_free(error_message);
> +        return detailed_error_message;
> +    }
> +
> +    return error_message;
> +}
> +
>  static int
>  virt_viewer_connect(VirtViewerApp *app)
>  {
> @@ -698,8 +728,11 @@ virt_viewer_connect(VirtViewerApp *app)
>                                      oflags);
>      if (!priv->conn) {
>          if (!priv->auth_cancelled) {
> -            virt_viewer_app_simple_message_dialog(app, _("Unable to connect to libvirt with URI %s"),
> -                                                  priv->uri ? priv->uri : _("[none]"));
> +            gchar *error_message = virt_viewer_get_error_message_from_vir_error(self, virGetLastError());
> +
> +            virt_viewer_app_simple_message_dialog(app, error_message);
> +
> +            g_free(error_message);
>          }
>  
>          return -1;





More information about the virt-tools-list mailing list