aws / aws/aws-tools-for-powershell

Audit use of terminating errors

Open
#331 1 comment 1 reaction 0 assignees View on GitHub
breaking-change feature-request module/powershell-cmdlets needs-major-version p2 queued vNext
Dominant language
C#
Stars
298
Forks
102
Avg merge
7d 17m
Merged PRs (30d)
2

Description

### Describe the feature

Review the use of terminating errors in AWS PowerShell cmdlets and only use terminating errors where absolutely necessary. Especially in "Get" verb cmdlets.

### Use Case

This started for me with Get-ACCTAlternateContact and the error "No contact of the inputted alternate contact type found." See:
https://github.com/aws/aws-tools-for-powershell/issues/327#issuecomment-1664853213
https://github.com/aws/aws-tools-for-powershell/issues/327#issuecomment-1672147917

However, I think it's a pretty widespread inconvenience in the AWS PowerShell codebase.

1. Terminating errors do not honor `-ErrorAction`. You have to use try/catch to handle the errors which is not friendly for interactive shell/command line. (less of a problem for scripted usage)
2. Terminating errors interrupt the pipeline:
```Get-Content .\AccountList.txt | ForEach-Object {Get-ACCTAlternateContact -AccountId $_ -AlternateContactType BILLING} | Export-Csv -Path .\billingContacts.csv``` - if there are 5 items and a terminating error on item 3, the remaining items are not processed.

@jnunn-aws says this is by according to PowerShell precedent but most PowerShell "Get" verb cmdlets don't throw terminating 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 and honor `-ErrorAction`.

Unless it's really critical, I'd expect cmdlets to emit a non-terminating errors that I can use -ErrorAction on and that do not interrupt the pipeline.

### Proposed Solution

_No response_

### Other Information

_No response_

### Acknowledgements

- [ ] I may be able to implement this feature request
- [X] This feature might incur a breaking change

### AWS Tools for PowerShell version used

4.1.396

### PowerShell version used

Name Value
PSVersion 7.3.6
PSEdition Core
GitCommitId 7.3.6
OS Microsoft Windows 10.0.22621
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

### Operating System and version

Windows 11

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.