Skip to content

Erroneous, unmatched closing parenthesis for char array members #124

@spiderkeys

Description

@spiderkeys
  • Operating System:
    • x64 Linux - Ubuntu 20.04
  • Installation type:
    • From source
  • Version or commit hash:

Steps to reproduce issue

  1. Create a package that can generate types from IDL.
  2. Create an IDL message file with a char[4] type as one of the struct fields.
  3. Build the package and source the setup.bash
  4. Use ros2 topic pub <topic name> <any message type from package with IDL containing the char array> {} or ros2 topic echo <topic with type from that same package>
  5. ros2cli tool will fail with a traceback

Description

Ultimately, the root cause (as indicated at the end of the error message below) is an unmatched closing parenthesis which is generated for the char[] type in _msg.py.em.

This does not:

  • Happen for other types that I have tested like long[4] and short[4], only for char[4]
  • Happen for non-array char
  • Change based on array size (4 is just an example)

This issue seems to have been in the codebase for quite some time, but only started causing issues in a recent Rolling build that I performed about a week ago, so it seems like something changed that caused this to start happening at runtime. This may be related to this recent commit:
91df295#diff-0da744c3127964a8907eb35fc0b5c04e32eccd515d8cf7fb839ec80ebb82fa59

One clue is that the error for the offending struct happens even when publishing or subscribing to a topic with a different type than the char[] containing one within the same package, which I believe is caused by all types getting imported in <some package>/msg/__init__.py

Fix:

#125

Example

myorg_msgs/msg/TestMessage.idl

module myorg_msgs {
  module msg {
    struct TestMessage {
       char [4];
    };
  };
};

Command/error:

spiderkeys@spiderdesk:/opt/mr/myorg$ ros2 topic pub hello myorg_msgs/msg/TestMessage {}
Traceback (most recent call last):
  File "/opt/ros/install/bin/ros2", line 33, in <module>
    sys.exit(load_entry_point('ros2cli==0.10.1', 'console_scripts', 'ros2')())
  File "/opt/ros/install/lib/python3.8/site-packages/ros2cli/cli.py", line 67, in main
    rc = extension.main(parser=parser, args=args)
  File "/opt/ros/install/lib/python3.8/site-packages/ros2topic/command/topic.py", line 41, in main
    return extension.main(args=args)
  File "/opt/ros/install/lib/python3.8/site-packages/ros2topic/verb/pub.py", line 97, in main
    return main(args)
  File "/opt/ros/install/lib/python3.8/site-packages/ros2topic/verb/pub.py", line 108, in main
    return publisher(
  File "/opt/ros/install/lib/python3.8/site-packages/ros2topic/verb/pub.py", line 133, in publisher
    msg_module = get_message(message_type)
  File "/opt/ros/install/lib/python3.8/site-packages/rosidl_runtime_py/utilities.py", line 28, in get_message
    interface = import_message_from_namespaced_type(get_message_namespaced_type(identifier))
  File "/opt/ros/install/lib/python3.8/site-packages/rosidl_runtime_py/import_message.py", line 30, in import_message_from_namespaced_type
    module = importlib.import_module(
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/opt/mr/myorg/install/myorg_msgs/lib/python3.8/site-packages/myorg_msgs/msg/__init__.py", line 22, in <module>
    from myorg_msgs.msg._test_message import TestMessage  # noqa: F401
  File "/opt/mr/myorg/install/myorg_msgs/lib/python3.8/site-packages/myorg_msgs/msg/_test_message.py", line 134
    all(val >= 0 and val) < 256 for val in value)), \
                                                 ^
SyntaxError: unmatched ')'

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions