Skip to content

Commit a112c6d

Browse files
DvirDukhanCopilot
andcommitted
fix(analyzer): defensive skip when second_pass references untracked file
In source_analyzer.second_pass, the list of files we iterate can include paths that first_pass did not add to self.files (e.g. parse errors, LSP-induced timeouts, or rare edge cases where a candidate file is present in the input list but never makes it into the files map). Previously this raised KeyError and aborted the entire index. Hit on sympy/polys/distributedmodules.py during bench calibration of sympy-12481. Skip with a WARN log instead so a single bad file no longer takes down the whole index. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e52650b commit a112c6d

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

api/analyzers/source_analyzer.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,16 @@ def second_pass(self, graph: Graph, files: list[Path], path: Path) -> None:
180180
# Skip symbol resolution when no real LSP is available
181181
if isinstance(lsps.get(file_path.suffix), NullLanguageServer):
182182
continue
183-
file = self.files[file_path]
183+
file = self.files.get(file_path)
184+
if file is None:
185+
# first_pass skipped this file (e.g. parse error, empty,
186+
# or ignored after entering the candidate list). Skip
187+
# in second_pass too instead of crashing the whole index.
188+
logging.warning(
189+
"second_pass: %s not in files map (first_pass skipped it); skipping",
190+
file_path,
191+
)
192+
continue
184193
logging.info(f'Processing file ({i + 1}/{files_len}): {file_path}')
185194
for _, entity in file.entities.items():
186195
entity.resolved_symbol(lambda key, symbol, fp=file_path: analyzers[fp.suffix].resolve_symbol(self.files, lsps[fp.suffix], fp, path, key, symbol))

0 commit comments

Comments
 (0)