Skip to content

Commit 40851ae

Browse files
authored
Merge pull request #18687 from github/tausbn/python-print-file-path-on-context-error
Python: Print file path when logging context errors
2 parents 5773538 + 60d97e0 commit 40851ae

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

python/extractor/semmle/python/parser/tsg_parser.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ def resolve_node_id(id, node_attr):
196196
id = node_attr[id]["_skip_to"].id
197197
return id
198198

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

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

345345
# Set up context information, if any
346346
if "ctx" in expected_fields:
347-
node.ctx = get_context(id, node_attr, logger)
347+
node.ctx = get_context(id, node_attr, path, logger)
348348
# Set the fields.
349349
for field, val in attrs.items():
350350
if field.startswith("_"): continue

0 commit comments

Comments
 (0)