From 1f9a04268f6de7e9aa11073f0bf363aadc2ca29b Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 26 Oct 2023 10:54:17 +0000 Subject: core: ensure all errors returned in DBus operations are normalized We want to ensure that all errors reported via DBus operations are normalized to MM-specific errors. We don't want to return QMI or MBIM specific errors, as those are protocol specific and we don't want DBus clients to need to rely on knowing which is the protocol in use by the device. --- src/mm-iface-modem-simple.c | 70 ++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 42 deletions(-) (limited to 'src/mm-iface-modem-simple.c') diff --git a/src/mm-iface-modem-simple.c b/src/mm-iface-modem-simple.c index 2427773c..194c5c0b 100644 --- a/src/mm-iface-modem-simple.c +++ b/src/mm-iface-modem-simple.c @@ -469,7 +469,7 @@ connect_bearer_ready (MMBaseBearer *bearer, if (!mm_base_bearer_connect_finish (bearer, res, &error)) { mm_obj_warn (ctx->self, "couldn't connect bearer: %s", error->message); - g_dbus_method_invocation_take_error (ctx->invocation, error); + mm_dbus_method_invocation_take_error (ctx->invocation, error); connection_context_free (ctx); return; } @@ -489,7 +489,7 @@ create_bearer_ready (MMIfaceModem *self, ctx->bearer = mm_iface_modem_create_bearer_finish (self, res, &error); if (!ctx->bearer) { mm_obj_warn (ctx->self, "couldn't create bearer: %s", error->message); - g_dbus_method_invocation_take_error (ctx->invocation, error); + mm_dbus_method_invocation_take_error (ctx->invocation, error); connection_context_free (ctx); return; } @@ -507,7 +507,7 @@ packet_service_attach_in_3gpp_network_ready (MMIfaceModemSimple *self, if (!packet_service_attach_in_3gpp_network_finish (self, res, &error)) { mm_obj_warn (ctx->self, "packet service attach in 3GPP network failed: %s", error->message); - g_dbus_method_invocation_take_error (ctx->invocation, error); + mm_dbus_method_invocation_take_error (ctx->invocation, error); connection_context_free (ctx); return; } @@ -525,7 +525,7 @@ register_in_3gpp_or_cdma_network_ready (MMIfaceModemSimple *self, if (!register_in_3gpp_or_cdma_network_finish (self, res, &error)) { mm_obj_warn (ctx->self, "registration in network failed: %s", error->message); - g_dbus_method_invocation_take_error (ctx->invocation, error); + mm_dbus_method_invocation_take_error (ctx->invocation, error); connection_context_free (ctx); return; } @@ -554,19 +554,16 @@ wait_for_enabled_ready (MMIfaceModem *self, state = mm_iface_modem_wait_for_final_state_finish (self, res, &error); if (error) { mm_obj_warn (ctx->self, "failed waiting for final state: %s", error->message); - g_dbus_method_invocation_take_error (ctx->invocation, error); + mm_dbus_method_invocation_take_error (ctx->invocation, error); connection_context_free (ctx); return; } if (state < MM_MODEM_STATE_ENABLED) { mm_obj_warn (ctx->self, "failed waiting for enabled state: %s", mm_modem_state_get_string (state)); - g_dbus_method_invocation_return_error ( - ctx->invocation, - MM_CORE_ERROR, - MM_CORE_ERROR_WRONG_STATE, - "Couldn't wait for 'enabled': new state is '%s'", - mm_modem_state_get_string (state)); + mm_dbus_method_invocation_return_error (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE, + "Couldn't wait for 'enabled': new state is '%s'", + mm_modem_state_get_string (state)); connection_context_free (ctx); return; } @@ -584,7 +581,7 @@ enable_ready (MMBaseModem *self, if (!mm_base_modem_enable_finish (MM_BASE_MODEM (self), res, &error)) { mm_obj_warn (ctx->self, "failed enabling modem: %s", error->message); - g_dbus_method_invocation_take_error (ctx->invocation, error); + mm_dbus_method_invocation_take_error (ctx->invocation, error); connection_context_free (ctx); return; } @@ -603,7 +600,7 @@ wait_for_initialized_ready (MMIfaceModem *self, mm_iface_modem_wait_for_final_state_finish (self, res, &error); if (error) { mm_obj_warn (ctx->self, "failed waiting for final state: %s", error->message); - g_dbus_method_invocation_take_error (ctx->invocation, error); + mm_dbus_method_invocation_take_error (ctx->invocation, error); connection_context_free (ctx); return; } @@ -621,7 +618,7 @@ send_pin_ready (MMBaseSim *sim, if (!mm_base_sim_send_pin_finish (sim, res, &error)) { mm_obj_warn (ctx->self, "failed sending SIM PIN: %s", error->message); - g_dbus_method_invocation_take_error (ctx->invocation, error); + mm_dbus_method_invocation_take_error (ctx->invocation, error); connection_context_free (ctx); return; } @@ -642,7 +639,7 @@ update_lock_info_ready (MMIfaceModem *self, lock = mm_iface_modem_update_lock_info_finish (self, res, &error); if (error) { mm_obj_warn (ctx->self, "failed updating lock info: %s", error->message); - g_dbus_method_invocation_take_error (ctx->invocation, error); + mm_dbus_method_invocation_take_error (ctx->invocation, error); connection_context_free (ctx); return; } @@ -663,12 +660,9 @@ update_lock_info_ready (MMIfaceModem *self, !mm_simple_connect_properties_get_pin (ctx->properties)) { mm_obj_warn (ctx->self, "modem is locked with '%s'", mm_modem_lock_get_string (lock)); - g_dbus_method_invocation_return_error ( - ctx->invocation, - MM_CORE_ERROR, - MM_CORE_ERROR_UNAUTHORIZED, - "Modem is locked with '%s' code; cannot unlock it", - mm_modem_lock_get_string (lock)); + mm_dbus_method_invocation_return_error (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_UNAUTHORIZED, + "Modem is locked with '%s' code; cannot unlock it", + mm_modem_lock_get_string (lock)); connection_context_free (ctx); return; } @@ -679,11 +673,8 @@ update_lock_info_ready (MMIfaceModem *self, NULL); if (!sim) { mm_obj_warn (ctx->self, "SIM is not accessible"); - g_dbus_method_invocation_return_error ( - ctx->invocation, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Cannot unlock modem, couldn't get access to the SIM"); + mm_dbus_method_invocation_return_error_literal (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Cannot unlock modem, couldn't get access to the SIM"); connection_context_free (ctx); return; } @@ -703,9 +694,8 @@ completed_if_cancelled (ConnectionContext *ctx) /* Otherwise cancellable is valid and it's cancelled */ mm_obj_warn (ctx->self, "connection attempt cancelled"); - g_dbus_method_invocation_return_error ( - ctx->invocation, G_IO_ERROR, G_IO_ERROR_CANCELLED, - "Connection attempt cancelled"); + mm_dbus_method_invocation_return_error_literal (ctx->invocation, G_IO_ERROR, G_IO_ERROR_CANCELLED, + "Connection attempt cancelled"); connection_context_free (ctx); return TRUE; } @@ -896,14 +886,14 @@ connect_auth_ready (MMBaseModem *self, MMModemState current = MM_MODEM_STATE_UNKNOWN; if (!mm_base_modem_authorize_finish (self, res, &error)) { - g_dbus_method_invocation_take_error (ctx->invocation, error); + mm_dbus_method_invocation_take_error (ctx->invocation, error); connection_context_free (ctx); return; } ctx->properties = mm_simple_connect_properties_new_from_dictionary (ctx->dictionary, &error); if (!ctx->properties) { - g_dbus_method_invocation_take_error (ctx->invocation, error); + mm_dbus_method_invocation_take_error (ctx->invocation, error); connection_context_free (ctx); return; } @@ -912,7 +902,7 @@ connect_auth_ready (MMBaseModem *self, mm_log_simple_connect_properties (self, MM_LOG_LEVEL_INFO, " ", ctx->properties); if (!setup_cancellation (ctx, &error)) { - g_dbus_method_invocation_take_error (ctx->invocation, error); + mm_dbus_method_invocation_take_error (ctx->invocation, error); connection_context_free (ctx); return; } @@ -923,9 +913,8 @@ connect_auth_ready (MMBaseModem *self, MM_IFACE_MODEM_BEARER_LIST, &ctx->bearer_list, NULL); if (!ctx->bearer_list) { - g_dbus_method_invocation_return_error ( - ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, - "Couldn't get the bearer list"); + mm_dbus_method_invocation_return_error_literal (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Couldn't get the bearer list"); connection_context_free (ctx); return; } @@ -1024,7 +1013,7 @@ bearer_list_disconnect_bearers_ready (MMBearerList *bearer_list, if (!mm_bearer_list_disconnect_bearers_finish (bearer_list, res, &error)) { mm_obj_warn (ctx->self, "failed to disconnect bearers: %s", error->message); - g_dbus_method_invocation_take_error (ctx->invocation, error); + mm_dbus_method_invocation_take_error (ctx->invocation, error); } else { mm_obj_info (ctx->self, "all requested bearers disconnected"); mm_gdbus_modem_simple_complete_disconnect (ctx->skeleton, ctx->invocation); @@ -1041,7 +1030,7 @@ disconnect_auth_ready (MMBaseModem *self, GError *error = NULL; if (!mm_base_modem_authorize_finish (self, res, &error)) { - g_dbus_method_invocation_take_error (ctx->invocation, error); + mm_dbus_method_invocation_take_error (ctx->invocation, error); disconnection_context_free (ctx); return; } @@ -1055,11 +1044,8 @@ disconnect_auth_ready (MMBaseModem *self, MM_IFACE_MODEM_BEARER_LIST, &list, NULL); if (!list) { - g_dbus_method_invocation_return_error ( - ctx->invocation, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Couldn't get the bearer list"); + mm_dbus_method_invocation_return_error_literal (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Couldn't get the bearer list"); disconnection_context_free (ctx); return; } -- cgit v1.2.3-70-g09d2