Invalid calls to POST …/scale return JSON parse errors
- Dominant language
- Go
- Stars
- 17k
- Forks
- 2.1k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 105
Description
While reviewing #8207, I thought I’d manipulate the calls to `POST /v1/job/:job/scale` to see what would happen if I passed invalid `Count` values.
With `"Count":1.5` the response was:
```
json: cannot unmarshal number 1.5 into Go struct field ScalingRequest.Count of type int64
```
With `"Count":"xyz"` the response was:
```
json: cannot unmarshal string into Go struct field ScalingRequest.Count of type int64
```
Both of these responses came with HTTP status 400.
Example cURL
curl 'http://localhost:4300/v1/job/api/scale' \
-H 'content-type: application/json; charset=UTF-8' \
--data-binary '{"Count":"xyz","Reason":"Manual scaling event from the Nomad UI","Target":{"Group":"endpoints"},"Meta":{"Source":"nomad-ui"}}' \
It would be nice from an API consumer perspective for these responses to come as JSON, perhaps status 422?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the POST /v1/job/:job/scale handler and the ScalingRequest.Count decoding path. Reproduce the requests with fractional and string Count values, then inspect nearby API tests if available. Done means invalid Count inputs return a JSON error response with an agreed client-error status, rather than raw JSON parse errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100