Skip to content
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
Closed

New-Object ignores the -ErrorAction common parameter #8580

mklement0 opened this issue Jan 2, 2019 · 2 comments
Labels
Issue-Discussion the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif Resolution-Answered The question is answered. WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module

Comments

@mklement0
Copy link
Contributor

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)
@iSazonov iSazonov added Issue-Discussion the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module labels Jan 3, 2019
@kvprasoon
Copy link
Contributor

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

@mklement0
Copy link
Contributor Author

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 MicrosoftDocs/PowerShell-Docs#1583)

@iSazonov iSazonov added the Resolution-Answered The question is answered. label Jan 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Discussion the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif Resolution-Answered The question is answered. WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants