mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix the clean block for generated proxy function (#16827)
This commit is contained in:
@@ -1128,7 +1128,9 @@ clean
|
||||
// 1. the 'Clean' block doesn't propagate up any exception (terminating error);
|
||||
// 2. only one expression in the script, so nothing else needs to be stopped when invoking the method fails.
|
||||
return @"
|
||||
$steppablePipeline.Clean()
|
||||
if ($null -ne $steppablePipeline) {
|
||||
$steppablePipeline.Clean()
|
||||
}
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
@@ -478,6 +478,19 @@ Describe 'Function Pipeline Behaviour' -Tag 'CI' {
|
||||
## Dispose the steppable pipeline.
|
||||
$step.Dispose()
|
||||
}
|
||||
|
||||
It "Clean block runs fine in a proxy function when a dynamic parameter fails to bind" {
|
||||
$function:TestProxyGci = [scriptblock]::Create(
|
||||
[Management.Automation.ProxyCommand]::Create(
|
||||
(Get-Command Get-ChildItem)))
|
||||
|
||||
## The proxy function 'TestProxyGci' contains the 'dynamicparam' block, which will
|
||||
## run during parameter binding. However, the parameter binding failed, and thus
|
||||
## the 'begin', 'process', and 'end' blocks will not run, so '$steppablePipeline'
|
||||
## in the proxy function is null (never created). The 'clean' block will run anyway,
|
||||
## but it should skip calling '$steppablePipeline.Clean()' in this case.
|
||||
{ TestProxyGci -Attributes } | Should -Throw -ErrorId 'MissingArgument,TestProxyGci'
|
||||
}
|
||||
}
|
||||
|
||||
Context "'exit' statement in command" {
|
||||
|
||||
Reference in New Issue
Block a user