cloudflare/cloudflared · error

expected string slice found %T for %s

Error message

expected string slice found %T for %s

What it means

Returned by configFileSettings.StringSlice when the setting exists but the whole value is not a []interface{} (e.g. it is a single string, map, or scalar). The message reports the value's dynamic type and the setting name.

Source

Thrown at config/configuration.go:335

		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))
			for i, v := range slice {
				str, ok := v.(string)
				if !ok {
					return nil, fmt.Errorf("expected string, found %T for %v", i, v)
				}
				strSlice[i] = str
			}
			return strSlice, nil
		}
		return nil, fmt.Errorf("expected string slice found %T for %s", raw, name)
	}
	return nil, nil
}

func (c *configFileSettings) IntSlice(name string) ([]int, error) {
	if raw, ok := c.Settings[name]; ok {
		if slice, ok := raw.([]interface{}); ok {
			intSlice := make([]int, len(slice))
			for i, v := range slice {
				str, ok := v.(int)
				if !ok {
					return nil, fmt.Errorf("expected int, found %T for %v ", v, v)
				}
				intSlice[i] = str
			}
			return intSlice, nil
		}
		if v, ok := raw.([]int); ok {

View on GitHub (pinned to 2253eeeb25)

Solutions

  1. Use YAML list syntax in the config file: origins:\n - web.
  2. If a single value is acceptable, wrap it in a one-element list or handle a string at the call site.
  3. Verify the key name is the one defined as a list by the consumer.

Example fix

// before (config.yml)
origins: web
// after
origins:
  - web
Defensive patterns

Strategy: validation

Validate before calling

// Go
isList := func(v interface{}) bool { _, ok := v.([]interface{}); return ok }

Type guard

func asList(v interface{}) ([]interface{}, bool) { l, ok := v.([]interface{}); return l, ok }

Try / catch

ss, err := settings.StringSlice("origins")
if err != nil {
    log.Printf("'origins' must be a YAML list: %v", err)
    return err
}

Prevention

When it happens

Trigger: Calling StringSlice(name) on a scalar setting, e.g. `origins: web` (single value instead of a list) or `origins: {a: b}`.

Common situations: Users specifying one item without YAML list syntax; config keys renamed so a string value is read as a slice.

Related errors


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