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

New-Object ignores the -ErrorAction common parameter #8580

Closed
mklement0 opened this Issue Jan 2, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@mklement0
Copy link
Contributor

mklement0 commented Jan 2, 2019

Steps to reproduce

New-Object NoSuch.Type -ErrorAction Ignore

Expected behavior

A quiet no-op.

Actual behavior

New-Object : Cannot find type [NoSuch.Type]: verify that the assembly containing this type is loaded.
...

That is, -ErrorAction Ignore was ignored.

Note that, by contrast, setting $ErrorActionPreference is respected.

PowerShell Core v6.2.0-preview.3 on macOS 10.14.2
PowerShell Core v6.2.0-preview.3 on Ubuntu 18.04.1 LTS
PowerShell Core v6.2.0-preview.3 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.471)
Windows PowerShell v5.1.17134.407 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.471)
@kvprasoon

This comment has been minimized.

Copy link
Contributor

kvprasoon commented Jan 5, 2019

If the change is just using WriteError instead of ThrowTerminatingError , I've a PR created for this.

@mklement0

This comment has been minimized.

Copy link
Contributor

mklement0 commented Jan 6, 2019

Thanks, @kvprasoon - and my apologies, because I should never have opened this issue:

New-Object rightfully reports a statement-terminating error, on which -ErrorAction has no effect.

(That setting $ErrorActionPreference does have an effect is a general inconsistency that is not specific to New-Object - see PowerShell/PowerShell-Docs#1583)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment