Title: Preventing setting 'Ignore' as the $ErrorActionPreference value is poorly enforced on the command line, and not at all in scripts · Issue #4348 · PowerShell/PowerShell · GitHub
Open Graph Title: Preventing setting 'Ignore' as the $ErrorActionPreference value is poorly enforced on the command line, and not at all in scripts · Issue #4348 · PowerShell/PowerShell
X Title: Preventing setting 'Ignore' as the $ErrorActionPreference value is poorly enforced on the command line, and not at all in scripts · Issue #4348 · PowerShell/PowerShell
Description: Related: #1759 The Ignore error-action value is meant to be used only with the -ErrorAction common parameter, not with the $ErrorActionPreference preference variable. An explicit check to prevent the latter was clearly implemented (as ev...
Open Graph Description: Related: #1759 The Ignore error-action value is meant to be used only with the -ErrorAction common parameter, not with the $ErrorActionPreference preference variable. An explicit check to prevent t...
X Description: Related: #1759 The Ignore error-action value is meant to be used only with the -ErrorAction common parameter, not with the $ErrorActionPreference preference variable. An explicit check to prevent t...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/4348
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Preventing setting 'Ignore' as the $ErrorActionPreference value is poorly enforced on the command line, and not at all in scripts","articleBody":"\u003csup\u003eRelated: #1759\u003c/sup\u003e\r\n\r\nThe `Ignore` error-action value is meant to be used only with the `-ErrorAction` _common parameter_, not with the `$ErrorActionPreference` _preference variable_.\r\n\r\nAn explicit check to prevent the latter was clearly implemented (as evidenced by error message `The value Ignore is not supported for an ActionPreference variable. The provided value should be used only as a \r\nvalue for a preference parameter, and has been replaced by the default value.`), but it doesn't / doesn't properly take effect.\r\n\r\n* On the **command line**, `$ErrorActionPreference = 'Ignore'` is **accepted _at first_**. When the next error occurs, it is the error message about the invalid `$ErrorActionPreference` value that surfaces instead of the actual error's, and _only at that point_ is `$ErrorActionPreference` **reset to `Continue`**.\r\n\r\n* In a **script**, `$ErrorActionPreference = 'Ignore'` is **accepted _and_ takes effect**. A contributing factor is that **preference variables in child scopes are not type-constrained,** so I presume that no validation takes place at assignment time - see #3483\r\n\r\n\r\nSteps to reproduce\r\n------------------\r\n\r\n* On the command line:\r\n\r\n```powershell\r\n# On the command line: set to invalid value, reflect it, then trigger an error, then reflect it again.\r\n\u003e $ErrorActionPreference = 'Ignore'; $ErrorActionPreference; 1 / 0; $ErrorActionPreference\r\n```\r\n\r\n* In a script (place code in a `*.ps1` file):\r\n\r\n```powershell\r\n$ErrorActionPreference = 'Ignore'; $ErrorActionPreference; 1/0; $ErrorActionPreference\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\n\r\n* Both on the command line and in a script:\r\n\r\n```none\r\nThe value Ignore is not supported for an ActionPreference variable. The provided value should be used only as a \r\nvalue for a preference parameter, and has been replaced by the default value.\r\n...\r\nContinue\r\nAttempted to divide by zero.\r\n...\r\nContinue\r\n```\r\n\r\nActual behavior\r\n---------------\r\n\r\n* On the command line:\r\n\r\n```none\r\nIgnore\r\n$ErrorActionPreference = 'Ignore'; $ErrorActionPreference; 1 / 0: The value Ignore is not supported for an ActionPreference variable. The provided value should be used \r\nonly as a value for a preference parameter, and has been replaced by the default value. For more information, see the Help topic, \"about_Preference_Variables.\"\r\n + CategoryInfo : NotSpecified: (:) [], NotSupportedException\r\n + FullyQualifiedErrorId : System.NotSupportedException\r\nContinue\r\n```\r\n\r\nThe value was accepted at first and retained until the next error occurred. The next error's message is mistakenly replaced with the invalid-$ErrorActionPreference-value error message, and the value is reset to `Continue` at that point.\r\n\r\n* In a script:\r\n\r\n```none\r\nIgnore\r\nIgnore\r\n```\r\n\r\nThe value was accepted, stayed in effect, and suppressed the statement-terminating error.\r\n\r\nEnvironment data\r\n----------------\r\n\r\n```powershell\r\nPowerShell Core v6.0.0-beta.4 on macOS 10.12.5\r\nPowerShell Core v6.0.0-beta.4 on Ubuntu 16.04.2 LTS\r\nPowerShell Core v6.0.0-beta.4 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\nWindows PowerShell v5.1.15063.413 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2017-07-26T16:15:06.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":15},"url":"https://github.com/4348/PowerShell/issues/4348"}
| 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:b8ee42f4-7443-a419-e998-cb1e944c8c77 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A490:186FB1:39DDF3:4E3A6B:6A5B654A |
| html-safe-nonce | ee095570a670ab3bbeaa9c6c08411fc5a767c24c6fcb3b50dd768a50006d085a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDkwOjE4NkZCMTozOURERjM6NEUzQTZCOjZBNUI2NTRBIiwidmlzaXRvcl9pZCI6IjE0NDU2ODIyMTgzNDE3MjE0MTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e98aa0186cadded1b111c24b4b15484a53619de34f020c7cadfae1599453953e |
| hovercard-subject-tag | issue:245776620 |
| 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/4348/issue_layout |
| twitter:image | https://opengraph.githubassets.com/10cd87afa2b277a3c4a3f69edf41c4f7162850c0d32813d4b50ee14414af1f31/PowerShell/PowerShell/issues/4348 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/10cd87afa2b277a3c4a3f69edf41c4f7162850c0d32813d4b50ee14414af1f31/PowerShell/PowerShell/issues/4348 |
| og:image:alt | Related: #1759 The Ignore error-action value is meant to be used only with the -ErrorAction common parameter, not with the $ErrorActionPreference preference variable. An explicit check to prevent t... |
| 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 | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| 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 | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width