Element Get method can raise "unable to *set*" error
marcoag opened this issue · 0 comments
Discussed in this PR .
Environment
SDFormat13
Description
When calling the method Get
from the Element
class, if the type is not matching the current value it might ultimately end up
here, where it tries to get the not-matching type on the Get
call and the current value of the Param
and tries to set it with the new type that was asked for in the initial Get
function. I don't know what's the use case for this, maybe is an effort to correct the type because it could have been parsed with a wrong one initially?
It would be very helpful if we can figure out the use case for the code, as it will help understand the need (or not) for it and if it can be refactored to not "set" when calling Get
.
Alternatively an easier/faster patch could be generalizing the message of ValueFromStringImpl
to make the error less confusing. However IMHO this might be slightly incorrect as the function is actually setting something so the error it produces is currently correct.
Steps to reproduce
Run a piece of code like:
sdf::ElementPtr elem = std::make_shared<sdf::Element>();
elem->AddAttribute("key", "std::string", "test", true, errors, "");
elem->Get<int>("key");
Output
Invalid argument. Unable to set value [test] for key[key].