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

  1. Use a bare boolean literal: `distinct_hosts = true`
  2. Or a string strconv.ParseBool accepts: "true", "1", "false", "0", etc. — never a number or list
  3. Check that HCL didn't decode your value as a number (drop quotes and use true/false)
  4. 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

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


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/d2a14efb51eb21e8. Report an issue: GitHub.