Skip to content

Guard os.listdir in PostProcessInterfaceDetailsList.parse() against missing dir and unrelated files#54

Merged
Joseph-Ellaway merged 2 commits into
PDBE-8507-interface-table-data-onlyfrom
copilot/fix-code-review-comment-53
May 26, 2026
Merged

Guard os.listdir in PostProcessInterfaceDetailsList.parse() against missing dir and unrelated files#54
Joseph-Ellaway merged 2 commits into
PDBE-8507-interface-table-data-onlyfrom
copilot/fix-code-review-comment-53

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 26, 2026

PostProcessInterfaceDetailsList.parse() called os.listdir unconditionally, risking FileNotFoundError when no interfaces were generated and inadvertently opening unrelated files in the directory.

Changes

  • Directory existence check — added os.path.isdir guard before os.listdir; logs a warning and returns early if the directory is absent
  • File filtering — restricts iteration to files matching interface_*.{json,json.gz} (driven by self.compressed) plus an os.path.isfile guard to skip subdirectories
  • Empty-set handling — warns and returns early when no matching interface files are found

Mirrors the pattern already established in CompileInterfaceSummaryJSON.parse().

if not os.path.isdir(self.path_interfaces):
    LOGGER.warning(...)
    return

ext = ".json.gz" if self.compressed else ".json"
interface_files = [
    f
    for f in os.listdir(self.path_interfaces)
    if f.startswith("interface_") and f.endswith(ext)
    and os.path.isfile(os.path.join(self.path_interfaces, f))
]

if not interface_files:
    LOGGER.warning(...)
    return

…ror CompileInterfaceSummaryJSON approach

Agent-Logs-Url: https://github.com/PDBe-KB/pisa-analysis/sessions/a5c9fa4a-7b33-452b-8efb-694672b776b3

Co-authored-by: Joseph-Ellaway <69363546+Joseph-Ellaway@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code based on review comment Guard os.listdir in PostProcessInterfaceDetailsList.parse() against missing dir and unrelated files May 26, 2026
Copilot AI requested a review from Joseph-Ellaway May 26, 2026 12:53
@Joseph-Ellaway Joseph-Ellaway marked this pull request as ready for review May 26, 2026 13:15
Copilot AI review requested due to automatic review settings May 26, 2026 13:15
@Joseph-Ellaway Joseph-Ellaway merged commit a8a3df0 into PDBE-8507-interface-table-data-only May 26, 2026
1 check failed
@Joseph-Ellaway Joseph-Ellaway deleted the copilot/fix-code-review-comment-53 branch May 26, 2026 13:16
Copilot AI review requested due to automatic review settings May 26, 2026 13:41
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.

2 participants