Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix traceback raised on an expression list assignment #439

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

ericwb
Copy link
Contributor

@ericwb ericwb commented Apr 23, 2024

When there is an assignment using a pattern_list and expression_list, the current code will iterate through each assignment. However, the current code assumes it can use context['node'], which is not the expected node during the parse.

: Language(path, name) is deprecated. Use Language(ptr, name) instead.
  warn("{} is deprecated. Use {} instead.".format(old, new), FutureWarning)
logging initialized
Working on file: tests/unit/parsers/examples/expression_list_assignment.py
Exception occurred when executing rules against tests/unit/parsers/examples/expression_list_assignment.py. Run "precli --debug tests/unit/parsers/examples/expression_list_assignment.py" to see the full traceback.
  Exception string: cannot access local variable 'func_node' where it is not associated with a value
  Exception traceback: Traceback (most recent call last):
  File "/Users/ericwb/workspace/precli/precli/core/run.py", line 127, in parse_file
    return parser.parse(artifact)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ericwb/workspace/precli/precli/parsers/__init__.py", line 99, in parse
    self.visit([tree.root_node])
  File "/Users/ericwb/workspace/precli/precli/parsers/__init__.py", line 124, in visit
    visitor_fn(node.children)
  File "/Users/ericwb/workspace/precli/precli/parsers/python.py", line 31, in visit_module
    self.visit(nodes)
  File "/Users/ericwb/workspace/precli/precli/parsers/__init__.py", line 124, in visit
    visitor_fn(node.children)
  File "/Users/ericwb/workspace/precli/precli/parsers/__init__.py", line 124, in visit
    visitor_fn(node.children)
  File "/Users/ericwb/workspace/precli/precli/parsers/python.py", line 98, in visit_assignment
    self.visit_assignment(
  File "/Users/ericwb/workspace/precli/precli/parsers/python.py", line 145, in visit_assignment
    func_node=func_node,
              ^^^^^^^^^
UnboundLocalError: cannot access local variable 'func_node' where it is not associated with a value

When there is an assignment using a pattern_list and expression_list,
the current code will iterate through each assignment. However, the
current code assumes it can use context['node'], which is not the
expected node during the parse.

Signed-off-by: Eric Brown <eric.brown@securesauce.dev>
@ericwb ericwb merged commit 1bfc918 into securesauce:main Apr 23, 2024
7 checks passed
@ericwb ericwb deleted the exp_list_assign branch April 23, 2024 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant