Skip to content
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

uninformative crash and error message for invalid parameter override #1001

Open
christianrauch opened this issue Aug 18, 2022 · 2 comments
Open
Labels
help wanted Extra attention is needed

Comments

@christianrauch
Copy link

Bug report

Setting an invalid parameter override crashes the process and gives an uninformative error message.

Required Info:

  • Operating System: Ubuntu 22.04
  • Installation type: binaries
  • Version or commit hash: 5.3.1
  • DDS implementation: default
  • Client library (if applicable): rcl

Steps to reproduce issue

  1. sudo apt install ros-humble-demo-nodes-cpp
  2. ros2 run demo_nodes_cpp talker --ros-args -p bla

Expected behavior

An error message or warning informing about the missing value assignment should be shown. I.e. the message should say that -p bla is not a valid parameter override, but -p bla:=5 is.

Even better, the parameter bla should be set to uninitialised (ParameterType::PARAMETER_NOT_SET).

Actual behavior

Crash with:

[ERROR] [1660855233.229710370] [rcl]: Failed to parse global arguments
terminate called after throwing an instance of 'rclcpp::exceptions::RCLInvalidROSArgsError'
  what():  failed to initialize rcl: Couldn't parse parameter override rule: '-p bla'. Error: Expected lexeme type (22) not found, search ended at index 3, at ./src/rcl/lexer_lookahead.c:239, at ./src/rcl/arguments.c:343
[ros2run]: Aborted
@fujitatomoya
Copy link
Collaborator

I think that this is because application does not catch the exception from rclcpp::init (rcl_init)

# ros2 run demo_nodes_cpp add_two_ints_client 1 2 --ros-args -p bla
[ERROR] [1660931840.357026857] [rcl]: Failed to parse global arguments
terminate called after throwing an instance of 'rclcpp::exceptions::RCLInvalidROSArgsError'
  what():  failed to initialize rcl: Couldn't parse parameter override rule: '-p bla'. Error: Expected lexeme type (22) not found, search ended at index 3, at /root/ros2_ws/colcon_ws/src/ros2/rcl/rcl/src/rcl/lexer_lookahead.c:239, at /root/ros2_ws/colcon_ws/src/ros2/rcl/rcl/src/rcl/arguments.c:343
[ros2run]: Aborted

this can be with following patch,

diff --git a/demo_nodes_cpp/src/services/add_two_ints_client.cpp b/demo_nodes_cpp/src/services/add_two_ints_client.cpp
index 8442801..b0cdf0d 100644
--- a/demo_nodes_cpp/src/services/add_two_ints_client.cpp
+++ b/demo_nodes_cpp/src/services/add_two_ints_client.cpp
@@ -43,7 +43,12 @@ int main(int argc, char ** argv)
   // Force flush of the stdout buffer.
   setvbuf(stdout, NULL, _IONBF, BUFSIZ);
 
-  rclcpp::init(argc, argv);
+  try {
+    rclcpp::init(argc, argv);
+  } catch (const std::exception & exception) {
+    RCLCPP_ERROR(rclcpp::get_logger("rclcpp"), exception.what());
+    return EXIT_FAILURE;
+  }
 
   auto node = rclcpp::Node::make_shared("add_two_ints_client");
# ros2 run demo_nodes_cpp add_two_ints_client 1 2 --ros-args -p bla
[ERROR] [1660931652.776928271] [rcl]: Failed to parse global arguments
[ERROR] [1660931652.776993285] [rclcpp]: failed to initialize rcl: Couldn't parse parameter override rule: '-p bla'. Error: Expected lexeme type (22) not found, search ended at index 3, at /root/ros2_ws/colcon_ws/src/ros2/rcl/rcl/src/rcl/lexer_lookahead.c:239, at /root/ros2_ws/colcon_ws/src/ros2/rcl/rcl/src/rcl/arguments.c:343
[ros2run]: Process exited with failure 1

@clalancette
Copy link
Contributor

[rclcpp]: failed to initialize rcl: Couldn't parse parameter override rule: '-p bla'. Error: Expected lexeme type (22) not found, search ended at index 3, at /root/ros2_ws/colcon_ws/src/ros2/rcl/rcl/src/rcl/lexer_lookahead.c:239, at /root/ros2_ws/colcon_ws/src/ros2/rcl/rcl/src/rcl/arguments.c:343

I still think this error message isn't as useful as it could be. It's exposing a low-level detail (the lexer parse error), rather than the higher-level "you provided an parameter argument that is missing :=", which is arguably more useful to the end-user.

@clalancette clalancette added the help wanted Extra attention is needed label Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants