Title: -Verbose Changes (downgrades) the Error Behaviour · Issue #2247 · PowerShell/PowerShell · GitHub
Open Graph Title: -Verbose Changes (downgrades) the Error Behaviour · Issue #2247 · PowerShell/PowerShell
X Title: -Verbose Changes (downgrades) the Error Behaviour · Issue #2247 · PowerShell/PowerShell
Description: -Verbose changes (downgrades) the Error Action from a Stop to Continue. This is undocumented and confusing. Steps to reproduce Run this script $ErrorActionPreference = "Stop" $VerbosePreference = "continue" #safely creating a file for fi...
Open Graph Description: -Verbose changes (downgrades) the Error Action from a Stop to Continue. This is undocumented and confusing. Steps to reproduce Run this script $ErrorActionPreference = "Stop" $VerbosePreference = "...
X Description: -Verbose changes (downgrades) the Error Action from a Stop to Continue. This is undocumented and confusing. Steps to reproduce Run this script $ErrorActionPreference = "Stop" $VerbosePref...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/2247
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"-Verbose Changes (downgrades) the Error Behaviour","articleBody":"-Verbose changes (downgrades) the Error Action from a Stop to Continue. This is undocumented and confusing.\r\n## Steps to reproduce\r\n\r\nRun this script\r\n\r\n```powershell\r\n$ErrorActionPreference = \"Stop\"\r\n$VerbosePreference = \"continue\"\r\n\r\n#safely creating a file for first run\r\nif(-Not (Test-Path test.txt))\r\n{\r\n new-item test.txt -Verbose \r\n}\r\n\r\n#create the same file\r\nnew-item test.txt -Verbose\r\nWrite-output 'This should not output because ErrorActionPreference is set to STOP'\r\n\r\n\r\nnew-item test.txt \r\nWrite-output 'This should never output because of the error above, and it doesn't'\r\n```\r\n## Expected behavior\r\n\r\n'This should not output because ErrorActionPreference is set to STOP', should not output\r\n## Actual behavior\r\n\r\n'This should not output because ErrorActionPreference is set to STOP' is output\r\n## Bug Location\r\n\r\nMshCommandRuntime.cs\r\n internal ActionPreference ErrorAction\r\n if (Verbose)\r\n return ActionPreference.Continue;\r\ndoesn't will downgrade a Stop\r\n## Proposed Solution\r\n\r\n```c#\r\n if (!_isErrorActionPreferenceCached)\r\n {\r\n bool defaultUsed = false;\r\n _errorAction = Context.GetEnumPreference\u003cActionPreference>(SpecialVariables.ErrorActionPreferenceVarPath, _errorAction, out defaultUsed);\r\n\r\n //Verbose should upgrade communication preferences, but not downgrade ErrorAction behavioural preferences \r\n if (Verbose)\r\n {\r\n // don't downgrade preferences \r\n if (!(_errorAction == ActionPreference.Stop || _errorAction == ActionPreference.Suspend))\r\n {\r\n _errorAction = ActionPreference.Continue;\r\n }\r\n }\r\n\r\n _isErrorActionPreferenceCached = true;\r\n }\r\n```\r\n## Environment data\r\n\r\n```\r\nMajor Minor Patch Label\r\n----- ----- ----- -----\r\n 6 0 0 alpha\r\n```\r\n","author":{"url":"https://github.com/timker","@type":"Person","name":"timker"},"datePublished":"2016-09-13T12:33:02Z","url":"https://github.com/PowerShell/PowerShell/issues/2247"}
| 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:ed796599-6074-c912-30e6-6e683d74fd8e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E5C8:31CC8C:178DBA:204856:6AFD8D0E |
| html-safe-nonce | b147b81cdc98625cf6a3acc09cc00751fbb56a3603f1bc6938cd5fdde4dd5ae4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNUM4OjMxQ0M4QzoxNzhEQkE6MjA0ODU2OjZBRkQ4RDBFIiwidmlzaXRvcl9pZCI6IjEyNTM1MzUwODM4NjA0MzAwOTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d6c599a53efbd8a1a793f579889ebc6400747f7891f51e2e02455ce33fe9c043 |
| hovercard-subject-tag | issue:176628300 |
| 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/2247/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cfc6f074b41a596428eff92587cc38536f6a47aeb2003bfa30aec39cb1629902/PowerShell/PowerShell/issues/2247 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cfc6f074b41a596428eff92587cc38536f6a47aeb2003bfa30aec39cb1629902/PowerShell/PowerShell/issues/2247 |
| og:image:alt | -Verbose changes (downgrades) the Error Action from a Stop to Continue. This is undocumented and confusing. Steps to reproduce Run this script $ErrorActionPreference = "Stop" $VerbosePreference = "... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | timker |
| hostname | github.com |
| expected-hostname | github.com |
| None | bc86424ef34a73b386237872800e922d149d65ba907f63d6f150a2dcb8433bea |
| 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 | 927a6c5ab1c32b38830f1b9d3050c0b9e9aa92e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width