{"record":{"id":"63e2fdabc7c2feac","repo":"cloudflare/cloudflared","slug":"expected-string-found-t-for-s","errorCode":null,"errorMessage":"expected string found %T for %s","messagePattern":"expected string found %T for (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/configuration.go","lineNumber":317,"sourceCode":"\treturn 0, nil\n}\n\nfunc (c *configFileSettings) Float64(name string) (float64, error) {\n\tif raw, ok := c.Settings[name]; ok {\n\t\tif v, ok := raw.(float64); ok {\n\t\t\treturn v, nil\n\t\t}\n\t\treturn 0, fmt.Errorf(\"expected float found %T for %s\", raw, name)\n\t}\n\treturn 0, nil\n}\n\nfunc (c *configFileSettings) String(name string) (string, error) {\n\tif raw, ok := c.Settings[name]; ok {\n\t\tif v, ok := raw.(string); ok {\n\t\t\treturn v, nil\n\t\t}\n\t\treturn \"\", fmt.Errorf(\"expected string found %T for %s\", raw, name)\n\t}\n\treturn \"\", nil\n}\n\nfunc (c *configFileSettings) StringSlice(name string) ([]string, error) {\n\tif raw, ok := c.Settings[name]; ok {\n\t\tif slice, ok := raw.([]interface{}); ok {\n\t\t\tstrSlice := make([]string, len(slice))\n\t\t\tfor i, v := range slice {\n\t\t\t\tstr, ok := v.(string)\n\t\t\t\tif !ok {\n\t\t\t\t\treturn nil, fmt.Errorf(\"expected string, found %T for %v\", i, v)\n\t\t\t\t}\n\t\t\t\tstrSlice[i] = str\n\t\t\t}\n\t\t\treturn strSlice, nil\n\t\t}\n\t\treturn nil, fmt.Errorf(\"expected string slice found %T for %s\", raw, name)","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/config/configuration.go#L299-L335","documentation":"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.","triggerScenarios":"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.","commonSituations":"YAML unquoted values that look numeric or boolean (port: 8080, enabled: true) but are consumed as strings; keys confused between sections of the config.","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."],"exampleFix":"// before (config.yml)\nprotocol: 2\n// after\nprotocol: \"h2mux\"","handlingStrategy":"validation","validationCode":"// Go\ntypeAssertString := func(v interface{}) (string, bool) { s, ok := v.(string); return s, ok }","typeGuard":"func asString(v interface{}) (string, bool) { s, ok := v.(string); return s, ok }","tryCatchPattern":"s, err := settings.String(\"hostname\")\nif err != nil {\n    log.Printf(\"'hostname' must be a quoted string: %v\", err)\n    return err\n}","preventionTips":["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"],"tags":["configuration","type-mismatch","string"],"backgroundTag":"config-type-mismatch","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}