{"record":{"id":"7e28921c63e29697","repo":"hashicorp/nomad","slug":"capacity-max-d-must-be-larger-than-capacity-min","errorCode":null,"errorMessage":"capacity_max (%d) must be larger than capacity_min (%d)","messagePattern":"capacity_max \\((.+?)\\) must be larger than capacity_min \\((.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/host_volumes.go","lineNumber":147,"sourceCode":"}\n\n// Validate verifies that the submitted HostVolume spec has valid field values,\n// without validating any changes or state (see ValidateUpdate).\nfunc (hv *HostVolume) Validate() error {\n\n\tvar mErr *multierror.Error\n\n\tif hv.ID != \"\" && !helper.IsUUID(hv.ID) {\n\t\tmErr = multierror.Append(mErr, fmt.Errorf(\"invalid ID %q\", hv.ID))\n\t}\n\n\tif hv.Name == \"\" {\n\t\tmErr = multierror.Append(mErr, errors.New(\"missing name\"))\n\t}\n\n\tif hv.RequestedCapacityMaxBytes < hv.RequestedCapacityMinBytes {\n\t\tmErr = multierror.Append(mErr, fmt.Errorf(\n\t\t\t\"capacity_max (%d) must be larger than capacity_min (%d)\",\n\t\t\thv.RequestedCapacityMaxBytes, hv.RequestedCapacityMinBytes))\n\t}\n\n\tfor _, cap := range hv.RequestedCapabilities {\n\t\terr := cap.Validate()\n\t\tif err != nil {\n\t\t\tmErr = multierror.Append(mErr, err)\n\t\t}\n\t}\n\n\tfor _, constraint := range hv.Constraints {\n\t\tif err := constraint.Validate(); err != nil {\n\t\t\tmErr = multierror.Append(mErr, fmt.Errorf(\"invalid constraint: %v\", err))\n\t\t}\n\t\tswitch constraint.Operand {\n\t\tcase ConstraintDistinctHosts, ConstraintDistinctProperty:\n\t\t\tmErr = multierror.Append(mErr, fmt.Errorf(\n\t\t\t\t\"invalid constraint %s: host volumes of the same name are always on distinct hosts\", constraint.Operand))","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/host_volumes.go#L129-L165","documentation":"HostVolume.Validate found the requested maximum capacity smaller than the requested minimum; capacity_max must be greater than or equal to capacity_min for a coherent volume request.","triggerScenarios":"Setting capacity_max below capacity_min in a host volume's requested capacity range, then validating/registering the volume.","commonSituations":"Swapped arguments when constructing the struct programmatically, unit mistakes (GB vs bytes) making the 'max' numerically smaller, or template variables resolved in the wrong order.","solutions":["Set capacity_max >= capacity_min in the volume request","Leave capacity_max unset if only a fixed capacity is needed"],"exampleFix":"// before\nminBytes = 107374182400; maxBytes = 1073741824\n// after\nminBytes = 1073741824; maxBytes = 107374182400","handlingStrategy":"validation","validationCode":"if hv.RequestedCapacityMaxBytes < hv.RequestedCapacityMinBytes {\n  return fmt.Errorf(\"capacity_max %d < capacity_min %d\", hv.RequestedCapacityMaxBytes, hv.RequestedCapacityMinBytes)\n}","typeGuard":null,"tryCatchPattern":"if err := hv.Validate(); err != nil {\n  return fmt.Errorf(\"check capacity_min/max ordering: %w\", err)\n}","preventionTips":["Always set max >= min","Centralize GiB->bytes conversion in one helper","Unit-test capacity struct construction"],"tags":["nomad","host-volumes","validation","capacity"],"backgroundTag":"min-max-range-inverted","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}