Skip to content

Commit b57bfd7

Browse files
committed
dialog: Print DBus errors where available
1 parent afd8be7 commit b57bfd7

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/dialog/unix/SDL_portaldialog.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ void SDL_Portal_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_Dialog
350350
}
351351

352352
SDL_DBusContext *dbus = SDL_DBus_GetContext();
353+
DBusError error;
353354
DBusMessage *msg;
354355
DBusMessageIter params, options;
355356
const char *signal_id = NULL;
@@ -361,6 +362,8 @@ void SDL_Portal_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_Dialog
361362

362363
const char *err_msg = validate_filters(filters, nfilters);
363364

365+
dbus->error_init(&error);
366+
364367
if (err_msg) {
365368
SDL_SetError("%s", err_msg);
366369
callback(userdata, NULL, -1);
@@ -459,7 +462,14 @@ void SDL_Portal_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_Dialog
459462
}
460463
dbus->message_iter_close_container(&params, &options);
461464

462-
DBusMessage *reply = dbus->connection_send_with_reply_and_block(dbus->session_conn, msg, DBUS_TIMEOUT_INFINITE, NULL);
465+
DBusMessage *reply = dbus->connection_send_with_reply_and_block(dbus->session_conn, msg, DBUS_TIMEOUT_INFINITE, &error);
466+
if (dbus->error_is_set(&error)) {
467+
SDL_SetError("Failed to open dialog via DBus, %s: %s", error.name, error.message);
468+
dbus->error_free(&error);
469+
callback(userdata, NULL, -1);
470+
goto cleanup;
471+
}
472+
463473
if (reply) {
464474
DBusMessageIter reply_iter;
465475
dbus->message_iter_init(reply, &reply_iter);
@@ -485,9 +495,16 @@ void SDL_Portal_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_Dialog
485495
}
486496

487497
SDL_snprintf(filter, filter_len, SIGNAL_FILTER"%s'", signal_id);
488-
dbus->bus_add_match(dbus->session_conn, filter, NULL);
498+
dbus->bus_add_match(dbus->session_conn, filter, &error);
489499
SDL_free(filter);
490500

501+
if (dbus->error_is_set(&error)) {
502+
SDL_SetError("Failed to set up DBus listener for dialog, %s: %s", error.name, error.message);
503+
dbus->error_free(&error);
504+
callback(userdata, NULL, -1);
505+
goto cleanup;
506+
}
507+
491508
SignalCallback *data = SDL_malloc(sizeof(SignalCallback));
492509
if (!data) {
493510
callback(userdata, NULL, -1);

0 commit comments

Comments
 (0)