-
Notifications
You must be signed in to change notification settings - Fork 79
Support creating node with ros args #1166
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds support for passing ROS command-line arguments when creating nodes by extending both the native and JavaScript APIs and verifying behavior with new tests.
- Introduced helper functions to marshal JS arrays into C-style
argvand detect unparsed ROS args - Extended the C++
CreateNodebinding and the JSNodeandcreateNodewrappers to acceptargsand auseGlobalArgumentsflag - Added TypeScript and JavaScript tests covering normal remapping, global arguments, and invalid-argument error handling
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/types/index.test-d.ts | Update TypeScript definitions to include args and useGlobalArguments parameters |
| test/test-node.js | Add JS tests for node argument parsing, global args, and error cases |
| src/rcl_utilities.h | Declare AbstractArgsFromNapiArray, FreeArgs, and HasUnparsedROSArgs helpers |
| src/rcl_utilities.cpp | Implement array-to-argv conversion, freeing logic, and unparsed-args detection |
| src/rcl_node_bindings.cpp | Parse argument arrays in CreateNode, add scope guards, and wire up use_global_args |
| src/rcl_context_bindings.cpp | Refactor context init to use helper functions for argv handling |
| lib/node.js | Update JS Node constructor and _init to accept args and useGlobalArguments |
| index.js | Update high-level rcl.createNode wrapper signature and docs |
Comments suppressed due to low confidence (3)
lib/node.js:87
- The
optionsparameter is never passed through to the nativecreateNodebinding, so user-suppliedNodeOptionsare ignored. Consider includingoptionsbeforeargswhen callingrclnodejs.createNodeand updating the C++ binding signature accordingly.
this.handle = rclnodejs.createNode(name, namespace, context.handle, args, useGlobalArguments);
test/types/index.test-d.ts:85
- A test for the default
useGlobalArgumentsbehavior (when omitted) would help ensure it actually defaults totrue. Consider adding a case that omits the boolean flag.
const nodeWithArgs = rclnodejs.createNode(
src/rcl_node_bindings.cpp:193
- [nitpick] The error message is generic. Including the original RCL error (e.g. via
rcl_get_error_string().str) would make troubleshooting argument parsing failures easier.
Napi::Error::New(env, "failed to parse arguments").ThrowAsJavaScriptException();
| reinterpret_cast<rcl_context_t*>(context_handle->ptr()); | ||
|
|
||
| rcl_node_t* node = reinterpret_cast<rcl_node_t*>(malloc(sizeof(rcl_node_t))); | ||
| Napi::Array jsArgv = info[3].As<Napi::Array>(); |
Copilot
AI
Jun 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argument indices no longer align with the JS wrapper signature (which also takes options). You should extract options from info[3], then shift jsArgv to info[4] and useGlobalArguments to info[5], with proper type checks and info.Length() validation.
src/rcl_context_bindings.cpp
Outdated
| } | ||
| free(argv); | ||
|
|
||
| FreeArgs(argv, argc); |
Copilot
AI
Jun 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider using a scope exit guard (e.g. RCPPUTILS_SCOPE_EXIT) for FreeArgs so that argv is always freed even if rcl_init or rcl_logging_configure throw an exception before reaching this line.
Adds support for passing ROS command-line arguments when creating nodes by extending both the native and JavaScript APIs and verifying behavior with new tests. - Introduced helper functions to marshal JS arrays into C-style `argv` and detect unparsed ROS args - Extended the C++ `CreateNode` binding and the JS `Node` and `createNode` wrappers to accept `args` and a `useGlobalArguments` flag - Added TypeScript and JavaScript tests covering normal remapping, global arguments, and invalid-argument error handling Fix: #1165
Adds support for passing ROS command-line arguments when creating nodes by extending both the native and JavaScript APIs and verifying behavior with new tests.
argvand detect unparsed ROS argsCreateNodebinding and the JSNodeandcreateNodewrappers to acceptargsand auseGlobalArgumentsflagFix: #1165