compiler error : get_if<> with a variant enum ?

Patrick Williams patrick at stwcx.xyz
Sat Oct 22 07:39:52 AEDT 2022


On Thu, Oct 20, 2022 at 04:32:40PM +0000, Francine Sauvage wrote:
> But, I get a runtime error as all my objects are different:
> 
> what():  xyz.openbmc_project.sdbusplus.Error.InvalidEnumString: An enumeration mapping was attempted for which no valid enumeration value exists.
> 
> Is there a way to add enum types to the variant of a ManagedObjects that potentially are NOT in the object interfaces/Properties ?
> 
> Or is there a way to filter the objects in ManagedObjects dbus calls ?

I'm sorry, I'm having trouble figuring out what you're trying to
accomplish or where it is having trouble.

I think you could unpack a `variant<YourEnumType, std::string>` from the
message (or dbus call result) and if it is your enumeration it'll be
interpreted as so but if not it will fall back to the string.  You can
even do `variant<Enum1, Enum2, Enum3>` and it'll turn into the correct
one.

The important thing is that you need to pass all possible types into the
variant when you attempt to unpack it.

Patrick Williams
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20221021/fb3ad21f/attachment.sig>


More information about the openbmc mailing list