DBUS_DEBUG("call %d: failed: %s", callId.id, params.getError().message.c_str());
return;
}
- detail::apply(callback, params.getValues());
+ try
+ {
+ detail::apply(callback, params.getValues());
+ } catch (...)
+ {
+ ERROR("unhandled exception");
+ }
}
};
auto handler = eldbus_proxy_signal_handler_add(connectionState.proxy, signalName.c_str(), listenerCallback, tmp);
z.getCallback = [ = ](const Eldbus_Message * src, Eldbus_Message_Iter * dst) -> ValueOrError<void> {
detail::emitNotification(eldbus_message_sender_get(src),
eldbus_message_path_get(src), interfaceName.c_str(), memberName.c_str(), DBusActionType::GETTER_RESPONSE);
- auto v = detail::apply(getter, std::tuple<>{});
- if (v)
+ try
+ {
+ auto v = detail::apply(getter, std::tuple<> {});
+ if (v) {
+ detail::signature<T>::set(dst, std::get<0>(v.getValues()));
+ DBUS_DEBUG("call %d: success", getterId.id);
+ return Success{};
+ }
+ DBUS_DEBUG("call %d: failed: %s", getterId.id, v.getError().message.c_str());
+ return v.getError();
+ } catch (std::exception &e)
{
- detail::signature<T>::set(dst, std::get<0>(v.getValues()));
- DBUS_DEBUG("call %d: success", getterId.id);
- return Success{};
+ return Error{ std::string("unhandled exception (") + e.what() + ")" };
+ } catch (...)
+ {
+ return Error{ "unhandled exception" };
}
- DBUS_DEBUG("call %d: failed: %s", getterId.id, v.getError().message.c_str());
- return v.getError();
};
}
if (setter) {
auto src_signature = eldbus_message_iter_signature_get(src_iter);
if (detail::signature<T>::get(src_iter, std::get<0>(value)))
{
- auto v = detail::apply(setter, std::move(value));
- if (v) {
- DBUS_DEBUG("call %d: success", setterId.id);
- return Success{};
+ try {
+ auto v = detail::apply(setter, std::move(value));
+ if (v) {
+ DBUS_DEBUG("call %d: success", setterId.id);
+ return Success{};
+ }
+ DBUS_DEBUG("call %d: failed: %s", setterId.id, v.getError().message.c_str());
+ free(src_signature);
+ return v.getError();
+ } catch (std::exception &e) {
+ return Error{ std::string("unhandled exception (") + e.what() + ")" };
+ } catch (...) {
+ return Error{ "unhandled exception" };
}
- DBUS_DEBUG("call %d: failed: %s", setterId.id, v.getError().message.c_str());
- free(src_signature);
- return v.getError();
}
DBUS_DEBUG("call %d: failed to unpack values, got signature '%s', expected '%s'", setterId.id,
src_signature, detail::signature<T>::sig().c_str());
auto args = detail::unpackValues<VEArgs>(callId, msg);
if (args)
{
- auto v = detail::apply(callback, std::move(args.getValues()));
- if (v) {
- DBUS_DEBUG("call %d: success", callId.id);
- ret = eldbus_message_method_return_new(msg);
- packValues(callId, ret, v);
- } else {
- DBUS_DEBUG("call %d: failed: %s", callId.id, v.getError().message.c_str());
- ret = eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", v.getError().message.c_str());
+ auto error = [&](const std::string & txt) {
+ DBUS_DEBUG("call %d: failed: %s", callId.id, txt.c_str());
+ ret = eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", txt.c_str());
+ };
+ try {
+ auto v = detail::apply(callback, std::move(args.getValues()));
+ if (v) {
+ DBUS_DEBUG("call %d: success", callId.id);
+ ret = eldbus_message_method_return_new(msg);
+ packValues(callId, ret, v);
+ } else {
+ error(v.getError().message);
+ }
+ } catch (std::exception &e) {
+ error(std::string("unhandled exception (") + e.what() + ")");
+ } catch (...) {
+ error("unhandled exception");
}
} else
{
auto connection = DBusServer::getCurrentConnection();
auto retCallback = [ = ](typename detail::dbus_interface_traits<T>::Ret v)
{
- DBUS_DEBUG(".");
if (v) {
- DBUS_DEBUG(".");
callState->reply = eldbus_message_method_return_new(callState->message.get());
packValues(callId, callState->reply, v);
} else {
callState->reply = eldbus_message_error_new(callState->message.get(), "org.freedesktop.DBus.Error.Failed", v.getError().message.c_str());
}
if (!callState->replyRunning) {
- DBUS_DEBUG(".");
eldbus_connection_send(connection.get(), callState->reply, NULL, NULL, -1);
}
};
auto args = detail::unpackValues<VEArgs>(callId, msg);
if (args)
{
- detail::apply(callback, std::move(retCallback), std::move(args.getValues()));
+ auto error = [&](const std::string & txt) {
+ if (!callState->reply) {
+ DBUS_DEBUG("call %d: failed: %s", callId.id, txt.c_str());
+ callState->reply = eldbus_message_error_new(callState->message.get(), "org.freedesktop.DBus.Error.Failed", txt.c_str());
+ }
+ };
+ try {
+ detail::apply(callback, std::move(retCallback), std::move(args.getValues()));
+ } catch (std::exception &e) {
+ error(std::string("unhandled exception (") + e.what() + ")");
+ } catch (...) {
+ error("unhandled exception");
+ }
+
callState->replyRunning = false;
ret = callState->reply;
} else