gazebosim/sdformat

Make the `sdf::Error` class compatible with other error codes/use cases

Open

#848 opened on Feb 9, 2022

View on GitHub
 (1 comment) (0 reactions) (0 assignees)C++ (122 forks)auto 404
enhancementhelp wanted

Repository metrics

Stars
 (216 stars)
PR merge metrics
 (PR metrics pending)

Description

Desired behavior

Currently, the sdf::Error class is only compatible with sdf::ErrorCode types. 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