pinocchio: getJointId should throw if out of range

Currently, if I query a joint that does not exist, I get the index of vector.end() which is out of bounds of njoints. Instead, if a joint does not exist, it should throw an exception (without me calling existJointName).

This relates to https://github.com/stack-of-tasks/pinocchio/blob/e038c7bf283b1df56a35014455e0e2d6f36e03ac/src/multibody/model.hxx#L209-L218

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 1
  • Comments: 19 (19 by maintainers)

Most upvoted comments

Sorry @gabrielebndn, I wrote a mistake. I wanted to say:

I do think this change will break existing code

My opinion on this is that this is an endless discussion that never goes well beyond Pinocchio. To me, there is no good answer whether an exception or some integer indicating a bad entry.

  • If you implement it, please take care to document it well, as it could break existing code relying on the old policy of returning njoints

It will. I suggest to:

  • change the prototype to: JointId getJointId (std::string name, bool throwIfNotFound = false).
  • and add to the TODO list for version 3 a rework of this function.

This delays the API change to version 3.