From b50acaf46a4261d60eaf0343b5cc07112aefc423 Mon Sep 17 00:00:00 2001 From: dhood Date: Fri, 1 Jun 2018 17:07:05 -0700 Subject: [PATCH 1/7] More descriptive error messages --- rcl/src/rcl/arguments.c | 3 ++- rcl/src/rcl/lexer_lookahead.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/rcl/src/rcl/arguments.c b/rcl/src/rcl/arguments.c index 7a60c9012..932135e61 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); diff --git a/rcl/src/rcl/lexer_lookahead.c b/rcl/src/rcl/lexer_lookahead.c index f2c882152..a8f988039 100644 --- a/rcl/src/rcl/lexer_lookahead.c +++ b/rcl/src/rcl/lexer_lookahead.c @@ -223,7 +223,8 @@ rcl_lexer_lookahead2_expect( } if (type != 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); From 15da6d1203746be47ecb917f63c4441b99d2c4da Mon Sep 17 00:00:00 2001 From: dhood Date: Fri, 1 Jun 2018 17:14:07 -0700 Subject: [PATCH 2/7] Special error message when lexeme not found --- rcl/src/rcl/lexer_lookahead.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rcl/src/rcl/lexer_lookahead.c b/rcl/src/rcl/lexer_lookahead.c index a8f988039..4bd617354 100644 --- a/rcl/src/rcl/lexer_lookahead.c +++ b/rcl/src/rcl/lexer_lookahead.c @@ -222,6 +222,11 @@ 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", type); + return RCL_RET_WRONG_LEXEME; + } RCL_SET_ERROR_MSG_WITH_FORMAT_STRING( buffer->impl->allocator, "Expected lexeme type %d, got %d at index %lu", type, lexeme, buffer->impl->text_idx); From ba4ee35b1b702c8d6580366a4e3506fceba83214 Mon Sep 17 00:00:00 2001 From: dhood Date: Fri, 1 Jun 2018 18:03:44 -0700 Subject: [PATCH 3/7] Output warning if ns remapping invalid --- rcl/src/rcl/arguments.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rcl/src/rcl/arguments.c b/rcl/src/rcl/arguments.c index 932135e61..8ccca7ca1 100644 --- a/rcl/src/rcl/arguments.c +++ b/rcl/src/rcl/arguments.c @@ -657,6 +657,10 @@ _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) { + RCUTILS_LOG_WARN_NAMED( + ROS_PACKAGE_NAME, "Namespace not remapped to a fully qualified name (found: %s)", ns_start); + } return ret; } From d838bd14cab98f1a838ff4aa9b5a5147522cad71 Mon Sep 17 00:00:00 2001 From: dhood Date: Fri, 1 Jun 2018 18:12:23 -0700 Subject: [PATCH 4/7] Output warning is ns remapping is invalid but starts with / --- rcl/src/rcl/arguments.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rcl/src/rcl/arguments.c b/rcl/src/rcl/arguments.c index 8ccca7ca1..58224a545 100644 --- a/rcl/src/rcl/arguments.c +++ b/rcl/src/rcl/arguments.c @@ -658,11 +658,20 @@ _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; + } // Copy namespace into rule const char * ns_end = rcl_lexer_lookahead2_get_text(lex_lookahead); From fd8fd58e7d4524c310c84ba86f2a4308615aaeb9 Mon Sep 17 00:00:00 2001 From: dhood Date: Mon, 4 Jun 2018 11:55:04 -0700 Subject: [PATCH 5/7] Add index to 'not found' error message --- rcl/src/rcl/lexer_lookahead.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rcl/src/rcl/lexer_lookahead.c b/rcl/src/rcl/lexer_lookahead.c index 4bd617354..cfc2fe4f3 100644 --- a/rcl/src/rcl/lexer_lookahead.c +++ b/rcl/src/rcl/lexer_lookahead.c @@ -224,7 +224,8 @@ rcl_lexer_lookahead2_expect( 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", type); + 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( From 24385eb7dab152c9fca70dc213e849a16887deca Mon Sep 17 00:00:00 2001 From: dhood Date: Mon, 4 Jun 2018 12:03:02 -0700 Subject: [PATCH 6/7] Distinguish between NONE and EOF --- rcl/include/rcl/lexer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rcl/include/rcl/lexer.h b/rcl/include/rcl/lexer.h index ae61b839e..8c41d2c5c 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 may not have been reached) RCL_LEXEME_NONE = 0, /// Indicates end of input has been reached RCL_LEXEME_EOF = 1, From 81aabf83d9382d65c24c8c51691155f7fb4257fb Mon Sep 17 00:00:00 2001 From: dhood Date: Mon, 4 Jun 2018 12:04:56 -0700 Subject: [PATCH 7/7] Firmer wording to avoid overlap in meaning --- rcl/include/rcl/lexer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rcl/include/rcl/lexer.h b/rcl/include/rcl/lexer.h index 8c41d2c5c..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 (end of input may not have been reached) + /// 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,