Skip to content

Fix scan failures caused by cleanup errors - #1905

Merged
Greg Villicana (grvillic) merged 1 commit into
microsoft:mainfrom
mpysson:dev/mpysson/fix-cleanup-failures
Oct 30, 2026
Merged

Greg Villicana (grvillic) merged 1 commit into
microsoft:mainfrom
mpysson:dev/mpysson/fix-cleanup-failures

Conversation

@mpysson

Copy link
Copy Markdown
Member

Prevent optional cleanup failures from aborting Component Detection scans.

Problem

Cleanup inventories the files and directories around a manifest before and after detector processing. If a directory disappears or enumeration encounters another I/O error, the exception can escape and fail the scan.

PipReport also deletes generated report files in a finally block. An I/O or permission error during deletion can escape that block, aborting the scan even after components have been recorded.

Solution

  • Handle IOException and UnauthorizedAccessException during cleanup inventory (FileComponentDetectorWithCleanup.cs:163–171).
  • Skip artifact cleanup when inventory cannot be completed, rather than risk deleting pre-existing files.
  • Handle the same exceptions when deleting generated PipReport files (PipReportComponentDetector.cs:348–360).
  • Log the affected path, exception type, and message at debug level without exception stack traces.

Other exception types are not suppressed by these cleanup handlers. The existing reportFile.Exists and reportFile.Delete() implementation is preserved.

Handle I/O and access errors during cleanup inventory and PipReport
report deletion without aborting scans. Skip artifact cleanup when
inventory is incomplete, and log the path, exception type, and message
without exception stack traces.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 993305b5-0b71-4bbb-9d82-c123b1da01d7

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Missing regression tests for cleanup inventory errors and generated pip-report deletion failures leave scan continuity and exception-handling boundaries insufficiently verified.

2 open issues
What changed in this PR

This PR prevents optional cleanup I/O and permission errors from aborting Component Detection scans while leaving other exception types unsuppressed.

Changes:

  • Handle inventory failures and skip cleanup when the inventory is incomplete.
  • Handle failures when deleting generated PipReport files.
  • Log affected paths, exception types, and messages at debug level without stack traces.
File Description
src/​Microsoft.ComponentDetection.Detectors/​pip/​PipReportComponentDetector.cs Handles I/O and permission errors during generated-report deletion.
src/​Microsoft.ComponentDetection.Contracts/​FileComponentDetectorWithCleanup.cs Extends inventory error handling to I/O failures and updates debug logging.

Review effort: Balanced

@grvillic
Greg Villicana (grvillic) merged commit d2b7149 into microsoft:main Oct 30, 2026
12 checks passed
@github-actions

Copy link
Copy Markdown

👋 Hi! It looks like you modified some files in the Detectors folder.
You may need to bump the detector versions if any of the following scenarios apply:

  • The detector detects more or fewer components than before
  • The detector generates different parent/child graph relationships than before
  • The detector generates different devDependencies values than before

If none of the above scenarios apply, feel free to ignore this comment 🙂

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.

3 participants