-
Notifications
You must be signed in to change notification settings - Fork 7.7k
ErrorAction Ignore broken for Invoke-WebRequest #21345
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
Comments
|
The common To trap terminating errors (both statement- and script-terminating ones), use Confusingly, the seemingly equivalent See also:
|
|
I think this needs to be changed then. As this is very counter-intuitive. So we'd probably have to add a new parameter like |
A lot has been written about this, and it's unlikely to change. And the results are not as expected. I remember complaining about the behaviour of the active directory commands more than 10 years ago... It is not quite as simple either.
Often we would LIKE code which goes something like or BUT IWR doesn't do " Which means the the calling script will ignore the error or Which downgrades it. It's not simply counter intuitive, there is no way to know if a given cmdlet (a) Prints errors and responds to -error action (b) Ejects and effectively ignores it (c) Uses both in different situations. More than one person has thought they have the perfect solution to this which turns out to be non-viable. |
|
For better or worse, the webcmdlets have built in "error checking". I think what you want is: Invoke-RestMethod -Uri 'https://http.codes/302' -MaximumRedirection 0 -SkipHttpErrorCheckWhich suppresses a feature to cause an error depending on the HTTP status. |
|
|
|
@agowa, it's an unfortunate example of where PowerShell's naming conventions - which do not formally cover parameter names - fall short: There are three different parameter prefixes that express the same fundamental concept: negation or opt-out:
To me, these variations could all have been reduced to Here's an example of what I believe to be a flawed explanation of why |
|
This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes. |
|
📣 Hey @agowa, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗 https://aka.ms/PSRepoFeedback |


Uh oh!
There was an error while loading. Please reload this page.
Prerequisites
Steps to reproduce
Invoke-WebRequest -Uri 'https://http.codes/302' -MaximumRedirection 0 -ErrorAction Ignorefunction test() { [CmdletBinding()] param() ; Invoke-WebRequest -Uri 'https://http.codes/302' -MaximumRedirection 0}; test -ErrorAction IgnoreEdit: It only works with CmdletBinding function-wrapping, if the wrapping function doesn't specify CmdletBinding it is also broken when wrapped.
Expected behavior
Not outputting an exception, both behaving equallyActual behavior
Error details
Environment data
Visuals
No response
The text was updated successfully, but these errors were encountered: