gazebosim / gazebosim/sdformat
Make the `sdf::Error` class compatible with other error codes/use cases
- Dominant language
- C++
- Stars
- 216
- Forks
- 125
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 14
Description
## Desired behavior
Currently, the [`sdf::Error` class](https://github.com/ignitionrobotics/sdformat/blob/sdformat12_12.3.0/include/sdf/Error.hh#L152) is only compatible with [`sdf::ErrorCode` types](https://github.com/ignitionrobotics/sdformat/blob/sdformat12_12.3.0/include/sdf/Error.hh#L40-L46). It would be nice to modify the `sdf::Error` class to be compatible with different error code types that may represent a different use case - for example, error codes that are specific to a SDF component (see the discussion in https://github.com/ignitionrobotics/sdformat/pull/836).
## Alternatives considered
1: extend `sdf::ErrorCode` to have different types of error codes. The drawback here is that `sdf::ErrorCode` could potentially have error codes that aren't directly related to SDF.
2: create separate error classes for different use cases that wrap `sdf::Error`. This is what was proposed in https://github.com/ignitionrobotics/sdformat/pull/836#issuecomment-1033480159. The drawback with this approach is that there is some code duplication and/or extra maintenance.
3: Make some (or all) of the methods in `sdf::ErrorCode` virtual, so that something like approach 2 above doesn't have code duplication. The drawback with this approach is that the derived class may not want all of the functionality from the `sdf::ErrorCode` class.
4: Make `sdf::Error` take something like a template type instead of the `sdf::ErrorCode` type. This may introduce unnecessary complexity, and would also break API/ABI.
## Implementation suggestion
See the alternatives considered section above for some ideas (I'm sure there are more that I did not come up with). Currently, there are no particular approaches that seem to stick out as "the best".
## Additional context
See links provided above for more context. This also might be useful: https://stackoverflow.com/questions/37700365/if-youre-in-the-we-dont-use-exceptions-camp-then-how-do-you-use-the-standar/37750064#37750064
Contributor guide
Research direction
Start with include/sdf/Error.hh, especially the sdf::Error and sdf::ErrorCode definitions, then read the discussion in pull request 836 and its linked comment. Compare the listed alternatives and determine an approach that supports component-specific error codes without unnecessary duplication or API/ABI breakage. Done means sdf::Error supports error code types beyond sdf::ErrorCode.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100