gazebosim / gazebosim/sdformat
Element Get method can raise "unable to *set*" error
- Dominant language
- C++
- Stars
- 216
- Forks
- 125
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 14
Description
Discussed in [this PR](https://github.com/gazebosim/sdformat/pull/1141/files/a00407d8fd10969119fe215726b71df4f87dd492#r1140655163) .
## 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](https://github.com/gazebosim/sdformat/blob/4464fbd413ff568f9a1c635f71fbaa4fae6b63e5/include/sdf/Param.hh#L729), 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();
elem->AddAttribute("key", "std::string", "test", true, errors, "");
elem->Get("key");
```
## Output
```
Invalid argument. Unable to set value [test] for key[key].
```
Contributor guide
Assessment
This issue has not been assessed yet.