{"record":{"id":"7f2c7ae291da3b78","repo":"hashicorp/nomad","slug":"distinct-hosts-should-be-set-to-true-or-false-v","errorCode":null,"errorMessage":"distinct_hosts should be set to true or false; %v","messagePattern":"distinct_hosts should be set to true or false; (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/volume_create_host.go","lineNumber":354,"sourceCode":"\n\t\t// If \"regexp\" is provided, set the operand\n\t\t// to \"regexp\" and the value to the \"RTarget\"\n\t\tif constraint, ok := m[api.ConstraintRegex]; ok {\n\t\t\tm[\"Operand\"] = api.ConstraintRegex\n\t\t\tm[\"RTarget\"] = constraint\n\t\t}\n\n\t\t// If \"set_contains\" is provided, set the operand\n\t\t// to \"set_contains\" and the value to the \"RTarget\"\n\t\tif constraint, ok := m[api.ConstraintSetContains]; ok {\n\t\t\tm[\"Operand\"] = api.ConstraintSetContains\n\t\t\tm[\"RTarget\"] = constraint\n\t\t}\n\n\t\tif value, ok := m[api.ConstraintDistinctHosts]; ok {\n\t\t\tenabled, err := parseBool(value)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"distinct_hosts should be set to true or false; %v\", err)\n\t\t\t}\n\n\t\t\t// If it is not enabled, skip the constraint.\n\t\t\tif !enabled {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tm[\"Operand\"] = api.ConstraintDistinctHosts\n\t\t\tm[\"RTarget\"] = strconv.FormatBool(enabled)\n\t\t}\n\n\t\tif property, ok := m[api.ConstraintDistinctProperty]; ok {\n\t\t\tm[\"Operand\"] = api.ConstraintDistinctProperty\n\t\t\tm[\"LTarget\"] = property\n\t\t}\n\n\t\t// Build the constraint\n\t\tvar c api.Constraint","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/volume_create_host.go#L336-L372","documentation":"Inside parseConstraints, a `distinct_hosts` constraint value is converted with parseBool. If that conversion fails (value is neither a bool nor a bool-parseable string), the error is wrapped as `distinct_hosts should be set to true or false; %v`.","triggerScenarios":"`nomad volume create` (host) where a constraint block contains `distinct_hosts` set to a non-boolean value such as \"yes\", 1, or an arbitrary string; note parseBool only accepts strconv.ParseBool-compatible strings (1/t/T/TRUE/true/True/0/f/F/FALSE/false/False) or actual bools.","commonSituations":"Using YAML-style truthiness (\"yes\"/\"on\"), JSON numbers (0/1), or quoted booleans with different capitalization like \"True\" with quotes is fine but \"Yes\" fails.","solutions":["Set `distinct_hosts = true` or `distinct_hosts = false` as a bare boolean","If it must be a string, use only values strconv.ParseBool accepts: 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False","Remove the distinct_hosts key if you don't want the constraint","Remember `false` simply skips the constraint, so deleting it is equivalent"],"exampleFix":"// before\nconstraint {\n  distinct_hosts = \"yes\"\n}\n\n// after\nconstraint {\n  distinct_hosts = true\n}","handlingStrategy":"validation","validationCode":"func validDistinctHosts(v interface{}) error {\n\tswitch t := v.(type) {\n\tcase bool:\n\t\treturn nil\n\tcase string:\n\t\tif _, err := strconv.ParseBool(t); err != nil {\n\t\t\treturn fmt.Errorf(\"distinct_hosts %q must be true or false\", t)\n\t\t}\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"distinct_hosts must be bool or bool-string, got %T\", v)\n\t}\n}","typeGuard":"func isBoolLike(v interface{}) bool {\n\tswitch t := v.(type) {\n\tcase bool:\n\t\treturn true\n\tcase string:\n\t\t_, err := strconv.ParseBool(t)\n\t\treturn err == nil\n\t}\n\treturn false\n}","tryCatchPattern":"if err := parseBool(value); err != nil {\n\treturn fmt.Errorf(\"set distinct_hosts to a bare true/false literal: %v\", err)\n}","preventionTips":["Always write distinct_hosts = true or false as a literal","Never use YAML-style yes/no/on/off","Never quote the value as \"Yes\" or \"YES\"","If using strings, restrict to strconv.ParseBool-accepted forms"],"tags":["hcl","nomad","constraint","boolean"],"backgroundTag":"invalid-boolean-value","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"}