hashicorp/nomad · error

invalid type %T

Error message

invalid type %T

What it means

parseQuotaMegabytes only accepts three input types: string (parsed as bytes), int (already in megabytes), and nil (zero). Any other Go type encountered in the quota file — e.g. float64 from JSON decoding, bool, or a list — triggers "invalid type %T" naming the offending Go type. It is a structural validation error for quota limit values.

Source

Thrown at command/quota_apply.go:373

		VariablesMB:   variablesLimit,
		HostVolumesMB: hostVolumesLimit,
	}, nil
}

func parseQuotaMegabytes(raw any) (int, error) {
	switch val := raw.(type) {
	case string:
		b, err := humanize.ParseBytes(val)
		if err != nil {
			return 0, fmt.Errorf("could not parse value as bytes: %v", err)
		}
		return int(b >> 20), nil
	case int:
		return val, nil
	case nil:
		return 0, nil
	default:
		return 0, fmt.Errorf("invalid type %T", raw)
	}
}

func parseDeviceResource(result *[]*api.RequestedDevice, list *ast.ObjectList) error {
	for idx, o := range list.Items {
		if l := len(o.Keys); l == 0 {
			return multierror.Prefix(fmt.Errorf("missing device name"), fmt.Sprintf("resources, device[%d]->", idx))
		} else if l > 1 {
			return multierror.Prefix(fmt.Errorf("only one name may be specified"), fmt.Sprintf("resources, device[%d]->", idx))
		}

		name := o.Keys[0].Token.Value().(string)

		// Check for invalid keys
		valid := []string{
			"name",
			"count",
		}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Change the value to an unquoted integer (megabytes) or a quoted byte string ("500MB").
  2. For JSON, ensure the field is a whole-number JSON int, not a decimal (1.5 -> 1 or use a string with units).
  3. Remove any bool/list/object values from limit fields; quotas accept only a single scalar size.
  4. Check the %T in the message to identify the exact offending type in your file.

Example fix

// before (JSON)
"host_volumes": 1.5
// after (JSON)
"host_volumes": 500
Defensive patterns

Strategy: type-guard

Validate before calling

// Ensure the JSON field decodes as int or string before use
switch v.(type) {
case int, string, nil: // allowed
default:
    return fmt.Errorf("quota limit must be int or string, got %T", v)
}

Type guard

func isScalarQuotaValue(v any) bool {
    switch v.(type) {
    case int, string, nil:
        return true
    default:
        return false
    }
}

Prevention

When it happens

Trigger: A JSON quota spec sets a limit to 1.5 (float), true, or an array; or an HCL value decodes to a type outside the accepted switch. Values like 500.0 from JSON decoding become float64 and hit this branch.

Common situations: Generating quota JSON programmatically and emitting floats or booleans; forgetting quotes on a string with units is fine (string case), but emitting "host_volumes": [] or true is not; YAML/JSON round-trips turning ints into floats.

Related errors


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