feat: Add continueOnError parameter to Folder.Clean()#1716
Conversation
Adds robust error handling to Folder.Clean() with a new overload: - continueOnError: When true, continues deleting remaining items even if some deletions fail (e.g., files in use by other processes) - Failed deletions are logged with warnings - All errors are aggregated and thrown as AggregateException at the end - Default behavior (continueOnError: false) throws immediately on first error This helps build pipelines handle locked files gracefully and provides better diagnostics when cleaning folders with problematic files. Fixes #1552 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
REVIEW: PR #1716 - Add continueOnError to Folder.Clean() SUMMARY: CRITICAL ISSUES: SUGGESTIONS:
VERDICT: |
There was a problem hiding this comment.
Pull request overview
This PR adds a continueOnError parameter to the Folder.Clean() method, enabling pipelines to continue deleting files even when some deletions fail. When enabled, all errors are aggregated and thrown as a single AggregateException at the end, with individual failures logged as warnings. The implementation maintains full backward compatibility through method overloads that default to the original fail-fast behavior.
Key Changes:
- Added new
Clean(bool removeReadOnlyAttribute, bool continueOnError)overload with error aggregation logic - Updated existing overloads to delegate to the new method with
continueOnError: falsedefault - Added try-catch blocks around directory and file deletion with exception filtering based on
continueOnErrorflag
| /// Thrown when <paramref name="continueOnError"/> is true and one or more deletions failed. | ||
| /// Contains all individual exceptions encountered during the operation. | ||
| /// </exception> | ||
| public void Clean(bool removeReadOnlyAttribute, bool continueOnError) |
There was a problem hiding this comment.
The new continueOnError parameter lacks test coverage. Consider adding tests that verify:
- When
continueOnError: true, the method continues deletion after encountering an error (e.g., by creating a file locked by another process) - When
continueOnError: true, failed deletions result in anAggregateExceptioncontaining all the individual errors - When
continueOnError: false(default), the method stops and throws on the first error as expected
The existing test file test/ModularPipelines.UnitTests/FolderTests.cs has tests for CleanFiles() and CleanFolders(), making it an appropriate location for these new test cases.
Summary
Clean(bool removeReadOnlyAttribute, bool continueOnError)overloadcontinueOnErroris true, continues deleting remaining items if some failAggregateExceptionat the endcontinueOnError: falseUse Cases
Example
Test plan
Fixes #1552
🤖 Generated with Claude Code