Skip to content

Name the port and the cause when a port name is rejected - #1225

Draft
dv-picknik wants to merge 1 commit into
BehaviorTree:masterfrom
dv-picknik:upstream/port-name-error-names-the-cause
Draft

dv-picknik wants to merge 1 commit into
BehaviorTree:masterfrom
dv-picknik:upstream/port-name-error-names-the-cause

Conversation

@dv-picknik

Copy link
Copy Markdown
Contributor

CreatePort, behind InputPort, OutputPort and BidirectionalPort, throws one fixed message whenever IsAllowedPortName fails. It never names the port, and it blames the first character even when the cause is a forbidden character. InputPort<double>("target.x") compiles and then throws at registerNodeType with:

The name of a port must not be `name` or `ID` and must start with an alphabetic character. Underscore is reserved.

This names the port and the check that failed:

Port Error
target.x Port name 'target.x' contains forbidden character '.'
goal pose Port name 'goal pose' contains forbidden character ' '
_foo Port name '_foo' must start with an alphabetic character, since a leading underscore is reserved
name Port name 'name' is a reserved attribute name

ThrowInvalidPortName builds the message in src/basic_types.cpp, next to IsAllowedPortName. It runs the same checks in the same order, so the reason it names is the one that failed. Because it lives in the library rather than the CreatePort template, the error path is no longer compiled into every translation unit that declares a port. It adds one exported symbol and changes no existing one.

Testing

  • pixi run build && pixi run test, 531/531.
  • NameValidation.CreatePort_ErrorNamesTheCause fails on master and passes here. For each failure path, including control characters, it checks that the message names the port and the right reason, and not a wrong one. Three inputs fail two checks at once, _a.b, .x and 1.5, which pins the check order.
  • pre-commit run is clean. clangd-21, installed per CONTRIBUTORS_GUIDE.md in an Ubuntu 24.04 container, reports All checks completed, 0 errors on both changed source files.

Related to #1215, where the same two rules disagree about a leading underscore.

Co-authored by Claude Opus 5.5

`CreatePort`, behind `InputPort`, `OutputPort` and `BidirectionalPort`, threw
one fixed message whenever `IsAllowedPortName` failed. It never named the port,
and it blamed the first character even when the cause was a forbidden
character, so `InputPort<double>("target.x")` reported:

  The name of a port must not be `name` or `ID` and must start with an
  alphabetic character. Underscore is reserved.

It now reports the port and the check that failed:

  Port name 'target.x' contains forbidden character '.'

`ThrowInvalidPortName` builds the message in the library, next to
`IsAllowedPortName`, so it checks in the same order and the reason it names is
always the one that failed. Keeping it out of the `CreatePort` template also
keeps the error path out of every plugin that declares a port. It is a new
exported symbol, so the change to the library's ABI is additive only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant