-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
Equivalent of bash 'set -e' (#3415) #3523
Conversation
Add preference to throw exception on $lastexitcode!=0, like bash ’set -e’. Only throw with commands *not* used in an expression/if/loop value. $NativeCommandPipeFailPreference=“continue”: like ‘set -e;set +o pipefail’. An exception is thrown for a native command giving a non-zero exit code, if it is the the last command in the pipeline. $NativeCommandPipeFailPreference=“silentlycontinue”: like ‘set +e’. No exception is thrown on non-zero exit codes. This is the default. $NativeCommandPipeFailPreference=“stop”: like ‘set -e;set -o pipefail’. An exception is thrown for a native command giving a non-zero exit code. With $NativeCommandExceptionPreference "continue" (the default), a RuntimeException is thrown, handing off to PowerShell error handling. With $NativeCommandExceptionPreference “stop”, an ExitException is thrown, terminating the shell regardless of other PowerShell error handling.
@PowerShell/powershell-committee could you please review this change? |
@PowerShell/powershell-committee discussed this briefly and has following observations:
Giving the larger implication of this change, committee feels we should have an RFC for this. The RFC should also consider other approaches as well, such as:
|
Thank you for reviewing this. I have begun compiling these details for a draft RFC as described. |
@mopadden Yes, PowerShell/PowerShell-RFC is right place. (Please read docs there.) |
set -e
(#3415)
Waiting on the RFC to be approved. |
This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days. |
This PR has be automatically close because it is stale. If you wish to continue working on the PR, please first update the PR, then reopen it. |
@SteveL-MSFT In place of this, how about providing the community with a hook ala function Enable-ThrowOnNativeCommandFailure {
$global:ExecutionContext.InvokeCommand.PostNativeCommandInvocationAction= {
param($Name, $EventArgs)
if ($EventArgs.ExitCode) {
throw "$Name $($EventArgs.Args) failed with exit code $($EventArgs.ExitCode)"
}
}
} Or maybe instead of throwing directly in the action handler, there could be a property on I have to say that as someone pushing PowerShell into |
@rkeithhill Please discuss in PowerShell/PowerShell-RFC#88. Or better pull new RFC with your proposal - I like it. |
@mopadden appears that @PowerShell/powershell-committee had closed on your RFC, can you continue with this PR? |
Quoting myself here so we have context:
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
Closing this PR as it doesn't match the RFC |
Add preference to throw exception on $lastexitcode!=0, like bash ’set -e’.
Only throw with commands not used in an expression/if/loop value.
$NativeCommandPipeFailPreference=“continue”: like ‘set -e;set +o pipefail’.
An exception is thrown for a native command giving a non-zero exit code,
if it is the the last command in the pipeline.
$NativeCommandPipeFailPreference=“silentlycontinue”: like ‘set +e’.
No exception is thrown on non-zero exit codes. This is the default.
$NativeCommandPipeFailPreference=“stop”: like ‘set -e;set -o pipefail’.
An exception is thrown for a native command giving a non-zero exit code.
With $NativeCommandExceptionPreference "continue" (the default),
a RuntimeException is thrown, handing off to PowerShell error handling.
With $NativeCommandExceptionPreference “stop”, an ExitException is thrown,
terminating the shell regardless of other PowerShell error handling.
Note: If PowerShell exits, the OS is given exit code 1 rather than forwarding the command exit code
to resolve #3415