CLI: acl policy read -format=json output is not json when policy is not found
- Dominant language
- Go
- Stars
- 30.1k
- Forks
- 4.6k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 43
Description
#### Overview of the Issue
`acl policy read` prints non-json for `--format=json`, whent the matching record is not found (both for `-name` and `id` option)
The output must be in json as the option is given.
Not sure how other "wrapping" command works - it may returns the custom struct (like output of `vault operator init -status`) - or bad response from the `/v1/acl/policies` endpoint.
(Related: #5904)
#### Reproduction Steps
1. Create a cluster with ACL enabled
1. run `consul acl policy read -format=json` with `-name` or `-id` option with non-existing value
Client output:
With `-name`
```
Error determining policy ID: Unexpected response code: 403 (ACL not found)
```
With `-id`
```
Error reading policy "d271fdd0-6740-4e71-bf6e-519f4439b660": Unexpected response code: 403 (ACL not found)
```
### Consul info for both Client and Server
Both server and client:
```
consul -version
Consul v1.9.1
Revision ca5c38943
```
### Operating system and Environment details
macOS
### Log Fragments
Server:
```
[ERROR] agent.http: Request error: method=GET url=/v1/acl/policies from=127.0.0.1:51947 error="ACL not found"
[DEBUG] agent.http: Request finished: method=GET url=/v1/acl/policies from=127.0.0.1:51947 latency=108.681µs
```
Contributor guide
Assessment
This issue has not been assessed yet.