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

Python: Print file path when logging context errors #18687

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python/extractor/semmle/python/parser/tsg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ def resolve_node_id(id, node_attr):
id = node_attr[id]["_skip_to"].id
return id

def get_context(id, node_attr, logger):
def get_context(id, node_attr, path, logger):
"""Gets the context of the node with the given `id`. This is either whatever is stored in the
`ctx` attribute of the node, or the result of dereferencing a sequence of `_inherited_ctx` attributes."""

while "ctx" not in node_attr[id]:
if "_inherited_ctx" not in node_attr[id]:
logger.error("No context for node {} with attributes {}\n".format(id, node_attr[id]))
logger.error("No context for node {} in file {} with attributes {}\n".format(id, path, node_attr[id]))
# A missing context is most likely to be a "load", so return that.
return ast.Load()
id = node_attr[id]["_inherited_ctx"].id
Expand Down Expand Up @@ -344,7 +344,7 @@ def parse(path, logger):

# Set up context information, if any
if "ctx" in expected_fields:
node.ctx = get_context(id, node_attr, logger)
node.ctx = get_context(id, node_attr, path, logger)
# Set the fields.
for field, val in attrs.items():
if field.startswith("_"): continue
Expand Down