Skip to content

Commit

Permalink
Issue a warning for evaluation errors in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke committed Jan 30, 2022
1 parent 88a4b28 commit 43ceb30
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/xacro/__init__.py
Expand Up @@ -997,7 +997,7 @@ def remove_previous_comments(node):
return


def eval_all(node, macros, symbols):
def eval_all(node, macros, symbols, comment_warning_issued=[False]):
"""Recursively evaluate node, expanding macros, replacing properties, and evaluating expressions"""
# evaluate the attributes
for name, value in node.attributes.items():
Expand Down Expand Up @@ -1099,8 +1099,21 @@ def eval_all(node, macros, symbols):

eval_all(node, macros, symbols)

elif node.nodeType == xml.dom.Node.TEXT_NODE or node.nodeType == xml.dom.Node.COMMENT_NODE:
elif node.nodeType == xml.dom.Node.TEXT_NODE:
node.data = unicode(eval_text(node.data, symbols))
elif node.nodeType == xml.dom.Node.COMMENT_NODE:
try:
node.data = unicode(eval_text(node.data, symbols))
except Exception as e:
if not comment_warning_issued[0]:
comment_warning_issued[0] = True
msg = unicode(e)
if not msg:
msg = repr(e)
warning("Error resolving an expression in a comment (skipping evaluation):")
warning(msg)
if verbosity > 0:
print_location()

node = next

Expand Down

0 comments on commit 43ceb30

Please sign in to comment.