{"record":{"id":"d2a14efb51eb21e8","repo":"hashicorp/nomad","slug":"v-couldn-t-be-converted-to-boolean-value","errorCode":null,"errorMessage":"%v couldn't be converted to boolean value","messagePattern":"(.+?) couldn't be converted to boolean value","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/volume_create_host.go","lineNumber":397,"sourceCode":"\n\t\t*result = append(*result, &c)\n\t}\n\n\treturn nil\n}\n\n// parseBool takes an interface value and tries to convert it to a boolean and\n// returns an error if the type can't be converted.\nfunc parseBool(value any) (bool, error) {\n\tvar enabled bool\n\tvar err error\n\tswitch data := value.(type) {\n\tcase string:\n\t\tenabled, err = strconv.ParseBool(data)\n\tcase bool:\n\t\tenabled = data\n\tdefault:\n\t\terr = fmt.Errorf(\"%v couldn't be converted to boolean value\", value)\n\t}\n\n\treturn enabled, err\n}\n","sourceCodeStart":379,"sourceCodeEnd":402,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/volume_create_host.go#L379-L402","documentation":"parseBool converts a value to a boolean: strings go through strconv.ParseBool, actual bools pass through, and any other type (numbers, arrays, objects) produces this error directly via fmt.Errorf. It is the low-level helper behind `distinct_hosts should be set to true or false`.","triggerScenarios":"A constraint value like `distinct_hosts = 1` or `distinct_hosts = [\"true\"]` reaches parseBool — the decoded HCL value is neither a string nor a bool, so the default branch fires.","commonSituations":"HCL decoding turns numeric literals into int64, so `distinct_hosts = 0/1` hits the default branch even though the intent was boolean; also occurs when a list or object is accidentally assigned.","solutions":["Use a bare boolean literal: `distinct_hosts = true`","Or a string strconv.ParseBool accepts: \"true\", \"1\", \"false\", \"0\", etc. — never a number or list","Check that HCL didn't decode your value as a number (drop quotes and use true/false)","Validate the constraint block contents before running the volume command"],"exampleFix":"// before\nconstraint {\n  distinct_hosts = 1\n}\n\n// after\nconstraint {\n  distinct_hosts = true\n}","handlingStrategy":"type-guard","validationCode":"func assertBoolOrBoolString(v interface{}) error {\n\tswitch v.(type) {\n\tcase bool:\n\t\treturn nil\n\tcase string:\n\t\tif _, err := strconv.ParseBool(v.(string)); err == nil {\n\t\t\treturn nil\n\t\t}\n\t}\n\treturn fmt.Errorf(\"%v couldn't be converted to boolean value\", v)\n}","typeGuard":"func isConvertibleToBool(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\tdefault:\n\t\treturn false\n\t}\n}","tryCatchPattern":"enabled, err := parseBool(value)\nif err != nil {\n\treturn fmt.Errorf(\"distinct_hosts=%v is not boolean; use true/false\", value)\n}","preventionTips":["Use bare boolean literals in HCL constraint blocks","Avoid numeric 0/1 — HCL decodes them as numbers and parseBool rejects them","Validate constraint values with a pre-flight check","Document that only bool and ParseBool-able strings are accepted"],"tags":["hcl","nomad","boolean","type-error"],"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"}