cloudflare/cloudflared · error
expected string found %T for %s
Error message
expected string found %T for %s
What it means
Type-mismatch error in configFileSettings.String: the named config-file setting exists but is not a string in the parsed YAML (e.g. an int or bool). The typed accessor returns the zero string plus this error rather than coercing the value.
Source
Thrown at config/configuration.go:317
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))
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)View on GitHub (pinned to 2253eeeb25)
Solutions
- Quote the value in the config file so it parses as a string (hostname: "example.com").
- Fix the key name if the wrong setting is being requested.
- At the call site, use the typed getter matching the actual type shown in %T and convert explicitly.
Example fix
// before (config.yml) protocol: 2 // after protocol: "h2mux"
Defensive patterns
Strategy: validation
Validate before calling
// Go
typeAssertString := func(v interface{}) (string, bool) { s, ok := v.(string); return s, ok } Type guard
func asString(v interface{}) (string, bool) { s, ok := v.(string); return s, ok } Try / catch
s, err := settings.String("hostname")
if err != nil {
log.Printf("'hostname' must be a quoted string: %v", err)
return err
} Prevention
- Quote string values in YAML even when they look like words
- Quote values that could parse as numbers or booleans
- Confirm the key name matches the consumer's expected setting
When it happens
Trigger: Calling String(name) on a setting stored as an int, bool, or slice — e.g. `hostname: 8080` or a boolean flag read as a string.
Common situations: YAML unquoted values that look numeric or boolean (port: 8080, enabled: true) but are consumed as strings; keys confused between sections of the config.
Related errors
- expected int found %T for %s
- expected duration found %T for %s
- expected float found %T for %s
- expected string, found %T for %v
- expected string slice found %T for %s
AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06).
Data as JSON: /api/errors/63e2fdabc7c2feac.
Report an issue: GitHub.