diff --git a/rcl/include/rcl/lexer.h b/rcl/include/rcl/lexer.h index ae61b839e..a818fea0b 100644 --- a/rcl/include/rcl/lexer.h +++ b/rcl/include/rcl/lexer.h @@ -30,7 +30,7 @@ extern "C" /// Type of lexeme found by lexical analysis. typedef enum rcl_lexeme_t { - /// Indicates no valid lexeme was found + /// Indicates no valid lexeme was found (end of input not reached) RCL_LEXEME_NONE = 0, /// Indicates end of input has been reached RCL_LEXEME_EOF = 1, diff --git a/rcl/src/rcl/arguments.c b/rcl/src/rcl/arguments.c index 7a60c9012..58224a545 100644 --- a/rcl/src/rcl/arguments.c +++ b/rcl/src/rcl/arguments.c @@ -110,7 +110,8 @@ rcl_parse_arguments( if (RCL_RET_OK == _rcl_parse_remap_rule(argv[i], allocator, rule)) { ++(args_impl->num_remap_rules); } else { - RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "arg %d error '%s'", i, rcl_get_error_string()); + RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "arg %d (%s) error '%s'", i, argv[i], + rcl_get_error_string()); rcl_reset_error(); args_impl->unparsed_args[args_impl->num_unparsed_args] = i; ++(args_impl->num_unparsed_args); @@ -656,6 +657,19 @@ _rcl_parse_remap_namespace_replacement( } ret = _rcl_parse_remap_fully_qualified_namespace(lex_lookahead); if (RCL_RET_OK != ret) { + if (RCL_RET_INVALID_REMAP_RULE == ret) { + // The name didn't start with a leading forward slash + RCUTILS_LOG_WARN_NAMED( + ROS_PACKAGE_NAME, "Namespace not remapped to a fully qualified name (found: %s)", ns_start); + } + return ret; + } + // There should be nothing left + ret = rcl_lexer_lookahead2_expect(lex_lookahead, RCL_LEXEME_EOF, NULL, NULL); + if (RCL_RET_OK != ret) { + // The name must have started with a leading forward slash but had an otherwise invalid format + RCUTILS_LOG_WARN_NAMED( + ROS_PACKAGE_NAME, "Namespace not remapped to a fully qualified name (found: %s)", ns_start); return ret; } diff --git a/rcl/src/rcl/lexer_lookahead.c b/rcl/src/rcl/lexer_lookahead.c index f2c882152..cfc2fe4f3 100644 --- a/rcl/src/rcl/lexer_lookahead.c +++ b/rcl/src/rcl/lexer_lookahead.c @@ -222,8 +222,15 @@ rcl_lexer_lookahead2_expect( return ret; } if (type != lexeme) { + if (RCL_LEXEME_NONE == lexeme || RCL_LEXEME_EOF == lexeme) { + RCL_SET_ERROR_MSG_WITH_FORMAT_STRING( + buffer->impl->allocator, "Expected lexeme type (%d) not found, search ended at index %lu", + type, buffer->impl->text_idx); + return RCL_RET_WRONG_LEXEME; + } RCL_SET_ERROR_MSG_WITH_FORMAT_STRING( - buffer->impl->allocator, "Expected %d got %d at %lu", type, lexeme, buffer->impl->text_idx); + buffer->impl->allocator, "Expected lexeme type %d, got %d at index %lu", type, lexeme, + buffer->impl->text_idx); return RCL_RET_WRONG_LEXEME; } return rcl_lexer_lookahead2_accept(buffer, lexeme_text, lexeme_text_length);