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

Raise custom error when node name is not found #413

Merged
merged 5 commits into from
Sep 17, 2019

Conversation

ivanpauno
Copy link
Member

@ivanpauno ivanpauno added the in review Waiting for review (Kanban column) label Aug 30, 2019
@ivanpauno ivanpauno self-assigned this Aug 30, 2019
return rclpy_implementation.rclpy_init(args if args is not None else sys.argv, context.handle)
global NodeNameNonExistentError
rclpy_implementation.rclpy_init(args if args is not None else sys.argv, context.handle)
NodeNameNonExistentError = rclpy_implementation.NodeNameNonExistentError
Copy link
Member

Choose a reason for hiding this comment

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

Why should this be the exposed C symbol? Wouldn't an exception defined in Python make more sense here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll weight in here, because I had a similar dilemma while figuring out how to raise appropriate exceptions upon failed argument parsing in rclpy: either defining an exception on Python and importing it from C or defining it in C and importing it on Python. And the latter seems more natural to me too.

But then this. Why is that C extensions cannot be imported at module level?

Copy link
Member Author

Choose a reason for hiding this comment

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

A little of history, see: #147

I would rather not limit C extensions to be loaded after the module. Instead, it should be possible to import them at module level too.
I have a solution in mind, that makes possible to import C extensions at module level, and shows a clearer relative path when testing. I will try if it works or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

My current solution has a big problem, the exception is only valid after rclpy_init. I will switch to an exception defined in Python if I don't successfully avoid the limitation of importing C extensions at module level.

…'t find a node name

Signed-off-by: ivanpauno <ivanpauno@ekumenlabs.com>
Signed-off-by: ivanpauno <ivanpauno@ekumenlabs.com>
Signed-off-by: ivanpauno <ivanpauno@ekumenlabs.com>
Signed-off-by: ivanpauno <ivanpauno@ekumenlabs.com>
@ivanpauno ivanpauno force-pushed the ivanpauno/add-error-for-non-existent-node branch from 8274aa1 to 0a4fe6f Compare September 16, 2019 19:27
Signed-off-by: ivanpauno <ivanpauno@ekumenlabs.com>
Copy link
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -83,6 +84,10 @@
SrvTypeRequest = TypeVar('SrvTypeRequest')
SrvTypeResponse = TypeVar('SrvTypeResponse')

# Re-export exception defined in _rclpy C extension.
# `Node.get_*_names_and_types_by_node` methods may raise this error.
NodeNameNonExistentError = _rclpy.NodeNameNonExistentError
Copy link
Contributor

Choose a reason for hiding this comment

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

@ivanpauno there was a previous comment from @dirk-thomas about not exporting to Python exceptions defined in C but the other way around. Since modules like rclpy.qos already import C extensions at the module level, this does not worsen the situation in any way.

So I'd say that we merge this as-is, to solve ros2/build_farmer#223, and then we work towards normalizing C extension use in rclpy -- whatever that means. There's a PR, #422, for it already. @dirk-thomas do you agree?

@ivanpauno
Copy link
Member Author

ivanpauno commented Sep 16, 2019

CI:
build up to: rclpy
test: rmw rmw_fastrtps_shared_cpp rmw_connext_shared_cpp rmw_opensplice_cpp rcl rclpy

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

@ivanpauno
Copy link
Member Author

I forgot to push a commit in ros2/rcl#492, again CI:

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

@ivanpauno
Copy link
Member Author

I'm merging this one, we can continue the discussion on how importing C extensions in #422.

@ivanpauno ivanpauno merged commit 87689dd into master Sep 17, 2019
@delete-merged-branch delete-merged-branch bot deleted the ivanpauno/add-error-for-non-existent-node branch September 17, 2019 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in review Waiting for review (Kanban column)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants