sdbusplus: bus.call() error handling

William Kennington wak at google.com
Tue Oct 16 06:10:43 AEDT 2018


If you don't use the sdbusplus bus.call() function you can skip
reading this message.

We currently have lots of code that looks something like:
auto resp = b.call(req);
if (resp.is_method_error())
{
    // handle errors
    // return
}
// continue doing

This code is broken since 55d6686ff38afef6597e734a9893116bc75475c6 was
introduced to add error handling to the bus.call() routine.

Unfortunately I also recommend at the time to change it to something like:
try
{
    auto resp = b.call(req);
    if (resp.is_method_error())
    {
        // handle errors
        // return
    }
    // continue doing work
}
catch(sdbusplus::exception::SdBusError& e)
{
    // handle errors
}

As it turns out, we don't need the is_method_error() check on the
response message at all, due to the underlying behavior of
sd_bus_call(). The error handling in that if statement is impossible
to reach and should be done in the catch block.

New code should look like:
try
{
    auto resp = b.call(req);
    // continue doing work
}
catch(sdbusplus::exception::SdBusError& e)
{
    // handle errors
}


More information about the openbmc mailing list