Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add package resource related utility functions to cpp API #27

Merged
merged 2 commits into from
Nov 9, 2017

Conversation

wjwwood
Copy link
Contributor

@wjwwood wjwwood commented Oct 28, 2017

These already existed in Python, see: #24

these already existed in Python, see: #24
@wjwwood wjwwood added enhancement New feature or request in review Waiting for review (Kanban column) labels Oct 28, 2017
@wjwwood wjwwood self-assigned this Oct 28, 2017
@wjwwood
Copy link
Contributor Author

wjwwood commented Oct 28, 2017

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

{
public:
AMENT_INDEX_CPP_PUBLIC
explicit PackageNotFoundError(const std::string & package_name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the package name be stored as a member in the custom exception class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 sure: 0d43992

AMENT_INDEX_CPP_PUBLIC
virtual ~PackageNotFoundError();

const std::string package_name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should the member be const? For a non-const instance of this class the user might want to change this member.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the package name is baked into the error message, and if you change this then it would be inconsistent with the what(), so you should only set it from the constructor. If you want a different package name in the error, I'd say create another object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't think that the class should prescribe the member to be const.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I don't agree. I've given a reason why it would be undesirable to change the package name after creation, but I haven't seen a reason why you would want to change it. I'm willing to change it if a convincing reason was given and that outweighs the downside I've already stated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package for which the exception was thrown does not seem like it should be modifiable after the fact or in the traceback/error handling thus keeping it const would make sense. And relaxing the const constraint in the future will always be easier than adding it if there is a use case that needs it than the reverse.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, I looked at making a setter and getter for the package_name, as a compromise, but that would require me to override the what() method (storage for what() is not exposed in the exception class) and provide my own storage which would be redundant. Also the what() function is noexcept:

http://en.cppreference.com/w/cpp/error/exception/what

So, the creating of the new std::string storage would need to be done in the setter, more or less what the constructor is doing. So I don't think it would be any easier (more efficient) than creating a new exception if you needed to change the package name (still don't know why you would need to do so).

@wjwwood
Copy link
Contributor Author

wjwwood commented Oct 31, 2017

New CI for the current state:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@wjwwood wjwwood merged commit 327994a into master Nov 9, 2017
@wjwwood wjwwood deleted the package_functions_for_cpp branch November 9, 2017 18:53
@wjwwood wjwwood removed the in review Waiting for review (Kanban column) label Nov 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants