cloudflare/cloudflared · error

expected float found %T for %s

Error message

expected float found %T for %s

What it means

Type-mismatch error in configFileSettings.Float64: the named config-file setting exists but its underlying value is not a float64 (e.g. a string or bool in the YAML). The accessor refuses the wrong-typed raw value and reports the Go type it actually found.

Source

Thrown at config/configuration.go:307

func (c *configFileSettings) Duration(name string) (time.Duration, error) {
	if raw, ok := c.Settings[name]; ok {
		switch v := raw.(type) {
		case time.Duration:
			return v, nil
		case string:
			return time.ParseDuration(v)
		}
		return 0, fmt.Errorf("expected duration found %T for %s", raw, name)
	}
	return 0, nil
}

func (c *configFileSettings) Float64(name string) (float64, error) {
	if raw, ok := c.Settings[name]; ok {
		if v, ok := raw.(float64); ok {
			return v, nil
		}
		return 0, fmt.Errorf("expected float found %T for %s", raw, name)
	}
	return 0, nil
}

func (c *configFileSettings) String(name string) (string, error) {
	if raw, ok := c.Settings[name]; ok {
		if v, ok := raw.(string); ok {
			return v, nil
		}
		return "", fmt.Errorf("expected string found %T for %s", raw, name)
	}
	return "", nil
}

func (c *configFileSettings) StringSlice(name string) ([]string, error) {
	if raw, ok := c.Settings[name]; ok {
		if slice, ok := raw.([]interface{}); ok {
			strSlice := make([]string, len(slice))

View on GitHub (pinned to 2253eeeb25)

Solutions

  1. Unquote the numeric value in the config file (threshold: 0.75).
  2. Use a locale-correct decimal point (period, not comma).
  3. If the source legitimately provides strings, read via String and strconv.ParseFloat at the call site.

Example fix

// before (config.yml)
threshold: "0.75"
// after
threshold: 0.75
Defensive patterns

Strategy: validation

Validate before calling

// Go
typeAssertFloat := func(v interface{}) (float64, bool) { f, ok := v.(float64); return f, ok }

Type guard

func asFloat64(v interface{}) (float64, bool) { f, ok := v.(float64); return f, ok }

Try / catch

f, err := settings.Float64("threshold")
if err != nil {
    log.Printf("'threshold' must be an unquoted number: %v", err)
    return err
}

Prevention

When it happens

Trigger: Calling Float64(name) on a setting stored as a string (e.g. `threshold: "0.75"`), bool, or int depending on the underlying decoder's behavior.

Common situations: Quoted floats in YAML/TOML configs; decimals written with commas; values supplied via environment/flags as strings landing in the settings map unconverted.

Related errors


AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06). Data as JSON: /api/errors/362137e3c0e48742. Report an issue: GitHub.