diff options
author | Alex Merry <dev@randomguy3.me.uk> | 2013-08-07 00:42:26 +0100 |
---|---|---|
committer | Alex Merry <dev@randomguy3.me.uk> | 2013-08-07 00:42:26 +0100 |
commit | e306c53d9e31c7ee09a131c765cbcec67fdd2565 (patch) | |
tree | 65ce45da763044c338a1f280bbdb46bd6aec9f8f /tikzit/src/gtk | |
parent | 4d76b39ddc5148f7212a87944509ad95828a9764 (diff) |
GTK: make presentError: methods cope with null errors
We can't always guarantee that library code will produce an error object
when things fail; default to "unknown error" if the error object is null
or does not have a message.
Diffstat (limited to 'tikzit/src/gtk')
-rw-r--r-- | tikzit/src/gtk/Window.m | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/tikzit/src/gtk/Window.m b/tikzit/src/gtk/Window.m index 7cb1e65..2d9e63a 100644 --- a/tikzit/src/gtk/Window.m +++ b/tikzit/src/gtk/Window.m @@ -394,47 +394,63 @@ static void update_paste_action (GtkClipboard *clipboard, GdkEvent *event, GtkAc } - (void) presentError:(NSError*)error { + const gchar *errorDesc = "unknown error"; + if (error && [error localizedDescription]) { + errorDesc = [[error localizedDescription] UTF8String]; + } GtkWidget *dialog = gtk_message_dialog_new (window, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", - [[error localizedDescription] UTF8String]); + errorDesc); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } - (void) presentError:(NSError*)error withMessage:(NSString*)message { + const gchar *errorDesc = "unknown error"; + if (error && [error localizedDescription]) { + errorDesc = [[error localizedDescription] UTF8String]; + } GtkWidget *dialog = gtk_message_dialog_new (window, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s: %s", [message UTF8String], - [[error localizedDescription] UTF8String]); + errorDesc); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } - (void) presentGError:(GError*)error { + const gchar *errorDesc = "unknown error"; + if (error && error->message) { + errorDesc = error->message; + } GtkWidget *dialog = gtk_message_dialog_new (window, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", - error->message); + errorDesc); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } - (void) presentGError:(GError*)error withMessage:(NSString*)message { + const gchar *errorDesc = "unknown error"; + if (error && error->message) { + errorDesc = error->message; + } GtkWidget *dialog = gtk_message_dialog_new (window, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s: %s", [message UTF8String], - error->message); + errorDesc); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } |