Skip to content

Commit

Permalink
Print warning if non-FQN namespace remapping passed (#248)
Browse files Browse the repository at this point in the history
* More descriptive error messages

* Special error message when lexeme not found

* Output warning if ns remapping invalid

* Output warning is ns remapping is invalid but starts with /

* Add index to 'not found' error message

* Distinguish between NONE and EOF

* Firmer wording to avoid overlap in meaning
  • Loading branch information
dhood authored Jun 4, 2018
1 parent 95b4147 commit e39201d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rcl/include/rcl/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 15 additions & 1 deletion rcl/src/rcl/arguments.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
9 changes: 8 additions & 1 deletion rcl/src/rcl/lexer_lookahead.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e39201d

Please sign in to comment.