-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Closed
Labels
Breaking-Changebreaking change that may affect usersbreaking change that may affect usersCommittee-ReviewedPS-Committee has reviewed this and made a decisionPS-Committee has reviewed this and made a decisionIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdlets-Corecmdlets in the Microsoft.PowerShell.Core modulecmdlets in the Microsoft.PowerShell.Core moduleWG-Languageparser, language semanticsparser, language semantics
Description
Write-Error is used to signal a non-terminating error, yet $? (the execution-status automatic variable) isn't set to $False in the caller's scope when it is called from an (advanced) function.
By contrast, if you use $PSCmdlet.WriteError from an advanced function, it is.
Steps to reproduce
function foo { Write-Error 'oh no' }; foo; $?
function foo2 { [cmdletbinding()] param() $PSCmdlet.WriteError((New-Object System.Management.Automation.ErrorRecord "oh no", $null, 'NotSpecified', $null)) }; foo2; $?Expected behavior
# (error details omitted)
$False
# (error details omitted)
$FalseActual behavior
# (error details omitted)
$True
# (error details omitted)
$FalseEnvironment data
PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on Darwin Kernel Version 16.5.0: Fri Mar 3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Breaking-Changebreaking change that may affect usersbreaking change that may affect usersCommittee-ReviewedPS-Committee has reviewed this and made a decisionPS-Committee has reviewed this and made a decisionIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdlets-Corecmdlets in the Microsoft.PowerShell.Core modulecmdlets in the Microsoft.PowerShell.Core moduleWG-Languageparser, language semanticsparser, language semantics