Print warning if non-FQN namespace remapping passed (#248)

* 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
This commit is contained in:
dhood 2018-06-04 14:40:32 -07:00 committed by GitHub
parent 95b4147009
commit e39201d6a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 3 deletions

View file

@ -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,

View file

@ -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;
}

View file

@ -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);