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

Get-EC2Tag cmdlet does not honor ErrorAction cmdlet parameter #327

Closed
GingerSnap-xx opened this issue Jul 5, 2023 · 11 comments
Closed

Get-EC2Tag cmdlet does not honor ErrorAction cmdlet parameter #327

GingerSnap-xx opened this issue Jul 5, 2023 · 11 comments
Assignees
Labels
bug This issue is a bug. module/powershell-cmdlets needs-review p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@GingerSnap-xx
Copy link

Describe the bug

GET-EC2TAG v 4.1.323 cmdlet does not honor ErrorAction parameter.

While writing an ebextension that calls Get-EC2Tag, it was deemed desirable to not write the error output to the logs as its not a problem if it cannot get the tags.

We tried making use of the ErrorAction cmdlet property and it does not suppress the error message.
Per the docs: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-7.3

It should suppress error messages when using Ignore.

Expected Behavior

Errors in Get-EC2Tag cmdlet should suppress error messages based on the ErrorAction variable.

Current Behavior

Errors in Get-EC2Tag cmdlet does not suppress error messages based on the ErrorAction variable.

Reproduction Steps

Call Get-EC2Tag in such a way that it produces an error (lack of authorization is our current example)
Error should be printed to console
Call Get-EC2Tag in the same way, but with -ErrorAction Ignore
Observe output

Possible Solution

Make the Get-EC2Tag cmdlet supress error messages based on ErrorAction cmdlet parameter

Additional Information/Context

No response

AWS Tools for PowerShell version used

4.1.323

PowerShell version used

5.1.17763

Operating System and version

Windows 2019 DataCenter

@GingerSnap-xx GingerSnap-xx added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 5, 2023
@GingerSnap-xx GingerSnap-xx changed the title (short issue description) Get-EC2Tag cmdlet does not honor ErrorAction cmdlet parameter Jul 5, 2023
@ashishdhingra
Copy link
Contributor

Similar issues #111 and #178 reported in the past, but these were closed due to staleness. Needs to be reviewed with the team.

@ashishdhingra ashishdhingra added needs-review p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Jul 5, 2023
@jnunn-aws
Copy link
Contributor

Hi GingerSnap-xx,

Thanks for sharing this issue.

Is this the code that I should use to reproduce this issue?

Get-EC2Tag -ErrorAction 'Ignore'

Please share the precise error message that you are receiving and trying to ignore. I should not assume that we are getting the same error message when I reproduce your steps. When I executed this command with permissions set to explicitly deny all access, I received this error message:

Get-EC2Tag: AWS was not able to validate the provided access credentials

@ashishdhingra ashishdhingra added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 24, 2023
@github-actions
Copy link

This issue has not received a response in 5 days. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jul 27, 2023
@GingerSnap-xx
Copy link
Author

GingerSnap-xx commented Jul 27, 2023 via email

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Jul 28, 2023
@dbaileyut
Copy link

This is also an issue with:
Get-ACCTAlternateContact -AccountId 111111111111 -AlternateContactType BILLING -ErrorVariable GetContactInfoError -ErrorAction SilentlyContinue

Example error that doesn't honor the -ErrorAction parameter - if there is no billing contact set:


ErrorRecord                 : No contact of the inputted alternate contact type found.
WasThrownFromThrowStatement : False
TargetSite                  : Void Throw()
Message                     : No contact of the inputted alternate contact type found.
Data                        : {}
InnerException              : System.InvalidOperationException: No contact of the inputted alternate contact type found.
                               ---> Amazon.Account.Model.ResourceNotFoundException: No contact of the inputted alternate contact type found.
                               ---> Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.
                                 at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
                                 at Amazon.Runtime.Internal.HttpHandler`1.InvokeAsync[T](IExecutionContext executionContext)
                                 at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)
                                 at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
                                 --- End of inner exception stack trace ---
                                 at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionStream(IRequestContext requestContext, IWebResponseData httpErrorResponse, HttpErrorResponseException exception, Stream responseStream)
                                 at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionAsync(IExecutionContext executionContext, HttpErrorResponseException exception)
                                 at Amazon.Runtime.Internal.ExceptionHandler`1.HandleAsync(IExecutionContext executionContext, Exception exception)
                                 at Amazon.Runtime.Internal.ErrorHandler.ProcessExceptionAsync(IExecutionContext executionContext, Exception exception)
                                 at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
                                 at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
                                 at Amazon.Runtime.Internal.Signer.InvokeAsync[T](IExecutionContext executionContext)
                                 at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
                                 at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
                                 at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)
                                 at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
                                 at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
                                 at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
                                 at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
                                 at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
                                 at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
                                 at Amazon.PowerShell.Cmdlets.ACCT.GetACCTAlternateContactCmdlet.CallAWSServiceOperation(IAmazonAccount client, GetAlternateContactRequest request)
                                 at Amazon.PowerShell.Cmdlets.ACCT.GetACCTAlternateContactCmdlet.Execute(ExecutorContext context)
                                 --- End of inner exception stack trace ---
                                 at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
HelpLink                    : 
Source                      : System.Private.CoreLib
HResult                     : -2146233087
StackTrace                  :    at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
                                 at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
                                 at <ScriptBlock>(Closure, FunctionContext)

Less ideal workaround, set $ErrorActionPreference to be what you want temporarily:

$ErrorActionPreference = 'SilentlyContinue'
Get-ACCTAlternateContact -AccountId 111111111111 -AlternateContactType BILLING -ErrorVariable GetContactInfoError 
$ErrorActionPreference = 'Continue'

@jnunn-aws
Copy link
Contributor

Hi Doug,

This behavior is expected. It honors the precedent set by PowerShell. The error that you have shared is a terminating error. The common parameter -ErrorAction only applies to non-terminating errors.

-ErrorAction
Determines how the cmdlet responds to a non-terminating error from the command. This parameter works only when the command generates a non-terminating error, such as those from the Write-Error cmdlet.

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-7.3

@dbaileyut
Copy link

dbaileyut commented Aug 9, 2023

Hi Doug,

This behavior is expected. It honors the precedent set by PowerShell. The error that you have shared is a terminating error. The common parameter -ErrorAction only applies to non-terminating errors.

-ErrorAction
Determines how the cmdlet responds to a non-terminating error from the command. This parameter works only when the command generates a non-terminating error, such as those from the Write-Error cmdlet.

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-7.3

Happy to raise a new issue so as not to sidetrack this one but my question is then: Why is this a terminating error? Most PowerShell "Get" verb cmdlets don't throw terminating errors on "not found" type errors.

E.g.:

Get-Item xxx -ErrorAction SilentlyContinue
Get-Job -Id 99 -ErrorAction SilentlyContinue
Get-Alias -Name xxx -ErrorAction SilentlyContinue
Get-Member -InputObject xxx -Name xxx -ErrorAction SilentlyContinue
Get-Module -Name xxx -ErrorAction SilentlyContinue

All of the above return non-terminating errors.

I would expect a non-terminating error and a $null return value.

@ashishdhingra
Copy link
Contributor

@dbaileyut Changing the current behavior would be a breaking change. As you suggested, feel free to open a new issue labeled as feature-request that the team would review and perhaps include in next major version bump.

@ashishdhingra
Copy link
Contributor

@GingerSnap-xx Please review the issue, there is a separate feature request #331 opened for team to review. Kindly confirm if it is fine to close this issue.

@ashishdhingra ashishdhingra added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Aug 25, 2023
@GingerSnap-xx
Copy link
Author

GingerSnap-xx commented Aug 26, 2023 via email

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. module/powershell-cmdlets needs-review p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

4 participants