New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add clean
block to script block as a peer to begin
, process
, and end
to allow easy resource cleanup
#15177
Add clean
block to script block as a peer to begin
, process
, and end
to allow easy resource cleanup
#15177
Conversation
990f70b
to
6c3dd9c
Compare
6c3dd9c
to
f2a9d87
Compare
This comment has been minimized.
This comment has been minimized.
It would be amazing for cmdlets to terminate whole script or process but acceptable for script blocks. |
e90ebbb
to
3ba0c31
Compare
test/powershell/Language/Scripting/PipelineBehaviour.Tests.ps1.bak
Outdated
Show resolved
Hide resolved
test/powershell/Language/Scripting/PipelineBehaviour.Tests.ps1.bak
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still reviewing, but submitting initial comments/questions.
src/System.Management.Automation/engine/CommandProcessorBase.cs
Outdated
Show resolved
Hide resolved
662159d
to
88c8aa5
Compare
you suggest that errors in the clean block will be captured in |
Errors in
I personally prefer to not make the @JamesWTruher The proposed error handling behavior already works with the changes in this PR, so I think it will be helpful if you can build this PR and play with it. You can also download the build artifacts from CIs, for example, the windows build can be downloaded here. Thanks for the review and I look forward to get more feedback from you! |
src/System.Management.Automation/engine/CommandProcessorBase.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs
Outdated
Show resolved
Hide resolved
1. not support directly invoking the 'clean' block of a script block. 2. not support a script block with the 'clean' block for '.ForEach' magic method. 3. make 'clean' block mimic the 'finally' clause 4. add a few more tests
9359f12
to
93305d4
Compare
Rebased the commits to resolve conflicts introduced by #16199 |
SSH remoting test run was cancelled due to an issue in the test pipeline, which was fixed by #16225 |
🎉 Handy links: |
…d `end` to allow easy resource cleanup (PowerShell#15177)
This is an alternate implementation of the
Clean
block in PowerShell. The original PR is #9900.This implementation doesn't rely on the
Dispose
method to run theClean
block, but instead makesClean
block more like a peer tobegin
,process
, andend
blocks.The updated RFC is currently under review: PowerShell/PowerShell-RFC#294
The doc issue for this feature: MicrosoftDocs/PowerShell-Docs#8090
The editor syntax PR: PowerShell/EditorSyntax#208
To-do check list:
SynchronousExecutionEnumerate
Exit
inClean
block?Exit
from within aClean
block terminates the execution in theClean
blockExitException
is not propagated out of theClean
blockfinally
behavior *]cleanup
toclean
{ clean { } }
? Noclean
block [manually checked]* The Ctrl+c behavior is still pending. The updated RFC discusses two different behaviors in the event of pipeline stopping in details in the
Pipeline Stopping Behavior
section. The current implementation in this PR mimics thefinally
clause behavior, but it keeps the changes inStopper
that would be needed to support non-cancellableclean
block execution.