Skip to content

Commit

Permalink
nicer error message
Browse files Browse the repository at this point in the history
  • Loading branch information
cgbaker committed Jan 8, 2021
1 parent 59271c6 commit cb1c018
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 4 additions & 2 deletions nomad/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1043,11 +1043,13 @@ func (j *Job) Scale(args *structs.JobScaleRequest, reply *structs.JobRegisterRes
if found.Scaling != nil {
if *args.Count < found.Scaling.Min {
return structs.NewErrRPCCoded(400,
"new scaling count cannot be less than the scaling policy minimum")
fmt.Sprintf("group count was less than scaling policy minimum: %d < %d",
*args.Count, found.Scaling.Min))
}
if found.Scaling.Max < *args.Count {
return structs.NewErrRPCCoded(400,
"new scaling count cannot be greater than the scaling policy maximum")
fmt.Sprintf("group count was greater than scaling policy maximum: %d > %d",
*args.Count, found.Scaling.Max))
}
}

Expand Down
9 changes: 4 additions & 5 deletions nomad/job_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6731,7 +6731,7 @@ func TestJobEndpoint_Scale_OutOfBounds(t *testing.T) {
structs.ScalingTargetGroup: job.TaskGroups[0].Name,
},
Count: helper.Int64ToPtr(pol.Max + 1),
Message: "too high",
Message: "out of bounds",
PolicyOverride: false,
WriteRequest: structs.WriteRequest{
Region: "global",
Expand All @@ -6740,13 +6740,12 @@ func TestJobEndpoint_Scale_OutOfBounds(t *testing.T) {
}
err = msgpackrpc.CallWithCodec(codec, "Job.Scale", scale, &resp)
require.Error(err)
require.Contains(err.Error(), "cannot be greater than")
require.Contains(err.Error(), "group count was greater than scaling policy maximum: 11 > 10")

scale.Count = helper.Int64ToPtr(pol.Min - 1)
scale.Message = "too low"
scale.Count = helper.Int64ToPtr(2)
err = msgpackrpc.CallWithCodec(codec, "Job.Scale", scale, &resp)
require.Error(err)
require.Contains(err.Error(), "cannot be less than")
require.Contains(err.Error(), "group count was less than scaling policy minimum: 2 < 3")
}

func TestJobEndpoint_Scale_NoEval(t *testing.T) {
Expand Down

0 comments on commit cb1c018

Please sign in to comment.