forked from Kistler-Group/sdbus-cpp
Catch sdbus-c++ exceptions flying from Proxy callbacks to libsystemd
This commit is contained in:
committed by
Urs Ritzmann
parent
6433b38ed1
commit
b4f5c0f46c
@ -593,7 +593,7 @@ namespace sdbus {
|
|||||||
{
|
{
|
||||||
reply >> args;
|
reply >> args;
|
||||||
}
|
}
|
||||||
catch (const sdbus::Error& e)
|
catch (const Error& e)
|
||||||
{
|
{
|
||||||
// Catch message unpack exceptions and pass them to the callback
|
// Catch message unpack exceptions and pass them to the callback
|
||||||
// in the expected manner to avoid propagating them up the call
|
// in the expected manner to avoid propagating them up the call
|
||||||
@ -641,17 +641,7 @@ namespace sdbus {
|
|||||||
tuple_of_function_input_arg_types_t<_Function> signalArgs;
|
tuple_of_function_input_arg_types_t<_Function> signalArgs;
|
||||||
|
|
||||||
// Deserialize input arguments from the signal message into the tuple
|
// Deserialize input arguments from the signal message into the tuple
|
||||||
try
|
signal >> signalArgs;
|
||||||
{
|
|
||||||
signal >> signalArgs;
|
|
||||||
}
|
|
||||||
catch (const sdbus::Error& e)
|
|
||||||
{
|
|
||||||
// The convenience API callback cannot handle an incoming signal with
|
|
||||||
// an unexpected payload, so catch and ignore this exception to avoid
|
|
||||||
// propagating it up the call stack to the event loop.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Invoke callback with input arguments from the tuple.
|
// Invoke callback with input arguments from the tuple.
|
||||||
sdbus::apply(callback, signalArgs);
|
sdbus::apply(callback, signalArgs);
|
||||||
|
@ -337,7 +337,7 @@ int Object::sdbus_method_callback(sd_bus_message *sdbusMessage, void *userData,
|
|||||||
{
|
{
|
||||||
callback(message);
|
callback(message);
|
||||||
}
|
}
|
||||||
catch (const sdbus::Error& e)
|
catch (const Error& e)
|
||||||
{
|
{
|
||||||
sd_bus_error_set(retError, e.getName().c_str(), e.getMessage().c_str());
|
sd_bus_error_set(retError, e.getName().c_str(), e.getMessage().c_str());
|
||||||
}
|
}
|
||||||
@ -371,7 +371,7 @@ int Object::sdbus_property_get_callback( sd_bus */*bus*/
|
|||||||
{
|
{
|
||||||
callback(reply);
|
callback(reply);
|
||||||
}
|
}
|
||||||
catch (const sdbus::Error& e)
|
catch (const Error& e)
|
||||||
{
|
{
|
||||||
sd_bus_error_set(retError, e.getName().c_str(), e.getMessage().c_str());
|
sd_bus_error_set(retError, e.getName().c_str(), e.getMessage().c_str());
|
||||||
}
|
}
|
||||||
@ -406,7 +406,7 @@ int Object::sdbus_property_set_callback( sd_bus */*bus*/
|
|||||||
{
|
{
|
||||||
callback(value);
|
callback(value);
|
||||||
}
|
}
|
||||||
catch (const sdbus::Error& e)
|
catch (const Error& e)
|
||||||
{
|
{
|
||||||
sd_bus_error_set(retError, e.getName().c_str(), e.getMessage().c_str());
|
sd_bus_error_set(retError, e.getName().c_str(), e.getMessage().c_str());
|
||||||
}
|
}
|
||||||
|
@ -240,15 +240,22 @@ int Proxy::sdbus_async_reply_handler(sd_bus_message *sdbusMessage, void *userDat
|
|||||||
proxy.m_CurrentlyProcessedMessage.store(nullptr, std::memory_order_relaxed);
|
proxy.m_CurrentlyProcessedMessage.store(nullptr, std::memory_order_relaxed);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto* error = sd_bus_message_get_error(sdbusMessage);
|
try
|
||||||
if (error == nullptr)
|
|
||||||
{
|
{
|
||||||
asyncCallData->callback(message, nullptr);
|
const auto* error = sd_bus_message_get_error(sdbusMessage);
|
||||||
|
if (error == nullptr)
|
||||||
|
{
|
||||||
|
asyncCallData->callback(message, nullptr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Error exception(error->name, error->message);
|
||||||
|
asyncCallData->callback(message, &exception);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (const Error&)
|
||||||
{
|
{
|
||||||
sdbus::Error exception(error->name, error->message);
|
// Intentionally left blank -- sdbus-c++ exceptions shall not bubble up to the underlying C sd-bus library
|
||||||
asyncCallData->callback(message, &exception);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -268,7 +275,15 @@ int Proxy::sdbus_signal_handler(sd_bus_message *sdbusMessage, void *userData, sd
|
|||||||
signalData->proxy.m_CurrentlyProcessedMessage.store(nullptr, std::memory_order_relaxed);
|
signalData->proxy.m_CurrentlyProcessedMessage.store(nullptr, std::memory_order_relaxed);
|
||||||
};
|
};
|
||||||
|
|
||||||
signalData->callback(message);
|
try
|
||||||
|
{
|
||||||
|
signalData->callback(message);
|
||||||
|
}
|
||||||
|
catch (const Error&)
|
||||||
|
{
|
||||||
|
// Intentionally left blank -- sdbus-c++ exceptions shall not bubble up to the underlying C sd-bus library
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user