Report errors in one place

Since the error is propagated to the main, report the error there.
To make it work GError VIRT_VIEWER_ERROR_FAILED is set for all
failing states and it is reported using virt_viewer_app_simple_message_dialog().
This commit is contained in:
Pavel Grunt 2015-03-20 10:35:56 +01:00 committed by Fabiano Fidêncio
parent 526e882368
commit 1a619f2383
4 changed files with 23 additions and 29 deletions

View File

@ -176,6 +176,9 @@ main(int argc, char **argv)
if (!virt_viewer_app_start(app, &error)) {
if (g_error_matches(error, VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_CANCELLED))
ret = 0;
else if (error) {
virt_viewer_app_simple_message_dialog(app, error->message);
}
goto cleanup;
}

View File

@ -1265,30 +1265,30 @@ retry_dialog:
vvfile = virt_viewer_file_new(path, &error);
g_free(path);
if (error) {
virt_viewer_app_simple_message_dialog(app, _("Invalid file %s"), guri);
g_prefix_error(&error, _("Invalid file %s: "), guri);
g_warning("%s", error->message);
goto cleanup;
}
g_object_get(G_OBJECT(vvfile), "type", &type, NULL);
} else if (virt_viewer_util_extract_host(guri, &type, NULL, NULL, NULL, NULL) < 0 || type == NULL) {
virt_viewer_app_simple_message_dialog(app, _("Cannot determine the connection type from URI"));
g_set_error_literal(&error,
VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED,
_("Cannot determine the connection type from URI"));
goto cleanup;
}
#ifdef HAVE_OVIRT
if (g_strcmp0(type, "ovirt") == 0) {
if (!create_ovirt_session(app, guri, &error)) {
if (error && !g_error_matches(error, VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_CANCELLED)) {
virt_viewer_app_simple_message_dialog(app,
_("Couldn't open oVirt session: %s"),
error->message);
}
g_prefix_error(&error, _("Couldn't open oVirt session: "));
goto cleanup;
}
} else
#endif
{
if (virt_viewer_app_create_session(app, type) < 0) {
virt_viewer_app_simple_message_dialog(app, _("Couldn't create a session for this type: %s"), type);
g_set_error(&error,
VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED,
_("Couldn't create a session for this type: %s"), type);
goto cleanup;
}
}
@ -1305,10 +1305,11 @@ retry_dialog:
#endif
if (!virt_viewer_app_initial_connect(app, &error)) {
const gchar *msg = error ? error->message :
_("Failed to initiate connection");
virt_viewer_app_simple_message_dialog(app, msg);
if (error == NULL) {
g_set_error_literal(&error,
VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED,
_("Failed to initiate connection"));
}
goto cleanup;
}
#ifdef HAVE_SPICE_GTK

View File

@ -115,6 +115,9 @@ int main(int argc, char **argv)
if (!virt_viewer_app_start(VIRT_VIEWER_APP(viewer), &error)) {
if (g_error_matches(error, VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_CANCELLED))
ret = 0;
else if (error) {
virt_viewer_app_simple_message_dialog(VIRT_VIEWER_APP(viewer), error->message);
}
goto cleanup;
}

View File

@ -746,7 +746,9 @@ virt_viewer_initial_connect(VirtViewerApp *app, GError **error)
virt_viewer_app_show_status(app, _("Checking guest domain status"));
if (virDomainGetInfo(dom, &info) < 0) {
g_debug("Cannot get guest state");
g_set_error_literal(&err, VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED,
_("Cannot get guest state"));
g_debug("%s", err->message);
goto cleanup;
}
@ -911,7 +913,6 @@ virt_viewer_connect(VirtViewerApp *app, GError **err)
g_set_error_literal(&error,
VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED,
error_message);
virt_viewer_app_simple_message_dialog(app, error_message);
g_free(error_message);
} else {
@ -924,21 +925,7 @@ virt_viewer_connect(VirtViewerApp *app, GError **err)
}
if (!virt_viewer_app_initial_connect(app, &error)) {
if (error != NULL) {
if (!g_error_matches(error, VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_CANCELLED)) {
VirtViewerWindow *main_window = virt_viewer_app_get_main_window(app);
GtkWidget *dialog = gtk_message_dialog_new(virt_viewer_window_get_window(main_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Failed to connect: %s",
error->message);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(GTK_WIDGET(dialog));
}
g_propagate_error(err, error);
}
g_propagate_prefixed_error(err, error, _("Failed to connect: "));
return -1;
}