Title: Write-Error in a function doesn't set automatic success variable $? to $False (doesn't set the execution status to indicate a non-terminating error) in the caller's scope · Issue #3629 · PowerShell/PowerShell · GitHub
Open Graph Title: Write-Error in a function doesn't set automatic success variable $? to $False (doesn't set the execution status to indicate a non-terminating error) in the caller's scope · Issue #3629 · PowerShell/PowerShell
X Title: Write-Error in a function doesn't set automatic success variable $? to $False (doesn't set the execution status to indicate a non-terminating error) in the caller's scope · Issue #3629 · PowerShell/PowerShell
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...
Open Graph 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 c...
X 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) functi...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/3629
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Write-Error in a function doesn't set automatic success variable $? to $False (doesn't set the execution status to indicate a non-terminating error) in the caller's scope","articleBody":"`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.\r\n\r\nBy contrast, if you use `$PSCmdlet.WriteError` from an advanced function, it is.\r\n\r\nSteps to reproduce\r\n------------------\r\n\r\n```powershell\r\nfunction foo { Write-Error 'oh no' }; foo; $?\r\nfunction foo2 { [cmdletbinding()] param() $PSCmdlet.WriteError((New-Object System.Management.Automation.ErrorRecord \"oh no\", $null, 'NotSpecified', $null)) }; foo2; $?\r\n```\r\n\r\n\r\nExpected behavior\r\n-----------------\r\n\r\n```powershell\r\n# (error details omitted)\r\n$False\r\n# (error details omitted)\r\n$False\r\n```\r\n\r\nActual behavior\r\n---------------\r\n\r\n```powershell\r\n# (error details omitted)\r\n$True\r\n# (error details omitted)\r\n$False\r\n```\r\n\r\nEnvironment data\r\n----------------\r\n\r\n```powershell\r\nPowerShell 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_64\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2017-04-23T14:20:42Z","url":"https://github.com/PowerShell/PowerShell/issues/3629"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2279bfa7-e0b0-ca30-0c97-cc9146840bc5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C5A8:1007B2:1CEF14:28CC09:6AFD51C1 |
| html-safe-nonce | 58ce7ad3498218af93375f9300b7beb966ff8277f16fb8c35bf7a061a9463d7f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNUE4OjEwMDdCMjoxQ0VGMTQ6MjhDQzA5OjZBRkQ1MUMxIiwidmlzaXRvcl9pZCI6Ijg5MDk3NTYwNjUwMjE1MTQxNzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 057a40637d4149ee12c456f09005ae8a52dcb56c9de54879bb91213d4a9e8019 |
| hovercard-subject-tag | issue:223639068 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/3629/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6cfa3b2971837b8606539a60e73e4cfa0efbad59de137327ca72079b1f3da7bc/PowerShell/PowerShell/issues/3629 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6cfa3b2971837b8606539a60e73e4cfa0efbad59de137327ca72079b1f3da7bc/PowerShell/PowerShell/issues/3629 |
| og:image:alt | 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 c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width