-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Closed
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Description
Note: Calling exit
from a function or method is unusual, but it works in functions and in class methods, but not from ScriptMethod
methods on custom objects, where it fails with an obscure error.
Steps to reproduce
pwsh -noprofile -c '($obj = [pscustomobject]::new()) | Add-Member -MemberType ScriptMethod Foo { exit 5 }; $obj.Foo()'
$LASTEXITCODE | Should -Be 5
Expected behavior
There should be no output, and the test should succeed.
Actual behavior
An error is reported, and the test fails, because the exit
statement wasn't effective (the exit code was implicitly set by the unexpected statement-terminating error, to 1
):
MethodInvocationException: Exception calling "Foo" with "0" argument(s): "System error."
InvalidResult:
Line |
1 | $LASTEXITCODE | Should -Be 5
| Expected 5, but got 1.
Environment data
PowerShell Core 7.0.0
Metadata
Metadata
Assignees
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime