Was discussing with @jpsnover a concern that if a cmdlet opens a resource (like a database connection) in Begin, and later in the pipeline an exception is thrown, End is not called to dispose of the connection.
Steps to reproduce
function a {
[cmdletbinding()]
param()
begin { "a:begin" }
process { 1 }
end { "a:end" }
}
function b {
[cmdletbinding()]
param([parameter(ValueFromPipeline=$true)]$a)
begin { "b:begin" }
process { $a; throw 'oops' }
}
a | b
Expected behavior
b:begin
a:begin
a:end
oops
At /Users/steve/test/end_not_called.ps1:15 char:19
+ process { $a; throw "oops" }
+ ~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (oops:String) [], RuntimeException
+ FullyQualifiedErrorId : oops
Actual behavior
b:begin
a:begin
oops
At /Users/steve/test/end_not_called.ps1:15 char:19
+ process { $a; throw "oops" }
+ ~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (oops:String) [], RuntimeException
+ FullyQualifiedErrorId : oops
Environment data
Name Value
---- -----
PSVersion 6.1.0-preview.1
PSEdition Core
GitCommitId v6.1.0-preview.1
OS Darwin 17.5.0 Darwin Kernel Version 17.5.0: Mon Mar 5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Was discussing with @jpsnover a concern that if a cmdlet opens a resource (like a database connection) in Begin, and later in the pipeline an exception is thrown, End is not called to dispose of the connection.
Steps to reproduce
Expected behavior
Actual behavior
Environment data