question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect Type for ClientGoalHandle.getResult

See original GitHub issue

Description The type definitions for ClientGoalHandle.getResult indicates that it returns Promise<ActionResult<T>>. It actually returns a type

interface ActionResultWithStatus<T> {
    status: number,
    result: ActionResult<T>
};
  • Library Version: 0.20.0
  • ROS Version: foxy
  • Platform / OS: ubuntu 20.04

Steps To Reproduce The following does not compile with tsc although if you cast result to any it does and result satisfies ActionResultWithStatus as described above.

import * as rclnodejs from 'rclnodejs'

async function main() {
  await rclnodejs.init();
  const node = new rclnodejs.Node('my_node');
  node.spin();
  const FollowJointTrajectory = rclnodejs.require('control_msgs/action/FollowJointTrajectory');

  const action_server = new rclnodejs.ActionServer(node, 'control_msgs/action/FollowJointTrajectory', '/my_action',
    (gh) => {
      gh.succeed();
      const result = new FollowJointTrajectory.Result();
      return result;
    }
  );

  const action_client = new rclnodejs.ActionClient(node, 'control_msgs/action/FollowJointTrajectory', '/my_action');
  await action_client.waitForServer();

  const goal = new FollowJointTrajectory.Goal();
  const gh = await action_client.sendGoal(goal);
  const result = await gh.getResult();
  console.log('Result: %j', result);
  console.log('Result Status: ', result.status);
  console.log('Result Result: ', result.result);
  node.stop();
}

main();

Expected Behavior compile without casting result to any

Actual Behavior

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
wayneparrottcommented, Oct 5, 2021

After a little debugging I’ve found 2 issues:

  1. the ClientGoalHandle.status property is intended to hold the status code (state id) across the goal processing lifecycle. Yet, internally this property is not being updated due to a race condition.
  2. this one is subjective and I’ll review with @minggangw. The await ClientGoalHandle.getResult() is leaking the internal {status,result} object. It should only return the result property. If we make this change then the TS types will correctly reflect the api’s behavior. If we choose to return the {status,result} object we will need to add an additional type declaration, e.g., <T>ResultWithStatus and modify the generator logic.

Looking at #1 now. Will discuss #2 with @minggangw

#1 - a race condition arises when the action-server is sends a status msg before returning a goal-request-response message. The latter msg cause the action-client to setup internal state for the goalClient. Yet, the preceding status msg depends up on the goalClient state to be established which it isn’t. Thus the status msg is ignored. A similar race condition arises when the goal request is completed.

0reactions
csmith-rtrcommented, Oct 6, 2021

@minggangw yes the example works correctly. The issue is that the typescript types do not match the value the promise resolves with.

Read more comments on GitHub >

github_iconTop Results From Across the Web

actionlib::SimpleActionClient< ActionSpec > Class Template ...
Cancel all goals that were stamped at and before the specified time. ResultConstPtr, getResult (). Get the Result of the current goal. SimpleClientGoalState ......
Read more >
JSDoc: Source: lib/action/client.js - Robot Web Tools
@param {function|string|object} typeClass - Type of the action. ... throw new TypeError('Invalid argument, must be type of ClientGoalHandle'); ...
Read more >
Actions — rclpy 0.6.1 documentation - ROS 2 Docs
The result of the returned Future is set to a ClientGoalHandle when receipt of the goal is acknowledged by an action server. Parameters....
Read more >
Issues - rclnodejs - Robot Web Tools - Geeks
Types should support overloaded Node methods. #873 opened 4 months ago by wayneparrott ... Incorrect Type for ClientGoalHandle.getResult.
Read more >
Cookie Consent doesnt save and doesnt disappear on Reload ...
<button type="button" data-cc="c-settings" class="cc-link">Let me ... Incorrect Type for ClientGoalHandle.getResult, 10, 2021-10-04, 2022-11-28.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found