hashicorp/nomad · error
%v couldn't be converted to boolean value
Error message
%v couldn't be converted to boolean value
What it means
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`.
Source
Thrown at command/volume_create_host.go:397
*result = append(*result, &c)
}
return nil
}
// parseBool takes an interface value and tries to convert it to a boolean and
// returns an error if the type can't be converted.
func parseBool(value any) (bool, error) {
var enabled bool
var err error
switch data := value.(type) {
case string:
enabled, err = strconv.ParseBool(data)
case bool:
enabled = data
default:
err = fmt.Errorf("%v couldn't be converted to boolean value", value)
}
return enabled, err
}
View on GitHub (pinned to 482b49bf1a)
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
Example fix
// before
constraint {
distinct_hosts = 1
}
// after
constraint {
distinct_hosts = true
} Defensive patterns
Strategy: type-guard
Validate before calling
func assertBoolOrBoolString(v interface{}) error {
switch v.(type) {
case bool:
return nil
case string:
if _, err := strconv.ParseBool(v.(string)); err == nil {
return nil
}
}
return fmt.Errorf("%v couldn't be converted to boolean value", v)
} Type guard
func isConvertibleToBool(v interface{}) bool {
switch t := v.(type) {
case bool:
return true
case string:
_, err := strconv.ParseBool(t)
return err == nil
default:
return false
}
} Try / catch
enabled, err := parseBool(value)
if err != nil {
return fmt.Errorf("distinct_hosts=%v is not boolean; use true/false", value)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- distinct_hosts should be set to true or false; %v
- failed to parse config:
- failed to convert task schema
- <combined HCL diagnostics from str.String()>
- Invalid or duplicate policy keys: %v
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/d2a14efb51eb21e8.
Report an issue: GitHub.