{"record":{"id":"7d6c7a1756535619","repo":"go-kratos/kratos","slug":"unsupported-key-s-format-s","errorCode":null,"errorMessage":"unsupported key: %s format: %s","messagePattern":"unsupported key: (.+?) format: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/options.go","lineNumber":96,"sourceCode":"func defaultDecoder(src *KeyValue, target map[string]any) error {\n\tif src.Format == \"\" {\n\t\t// expand key \"aaa.bbb\" into map[aaa]map[bbb]interface{}\n\t\tkeys := strings.Split(src.Key, \".\")\n\t\tfor i, k := range keys {\n\t\t\tif i == len(keys)-1 {\n\t\t\t\ttarget[k] = src.Value\n\t\t\t} else {\n\t\t\t\tsub := make(map[string]any)\n\t\t\t\ttarget[k] = sub\n\t\t\t\ttarget = sub\n\t\t\t}\n\t\t}\n\t\treturn nil\n\t}\n\tif codec := encoding.GetCodec(src.Format); codec != nil {\n\t\treturn codec.Unmarshal(src.Value, &target)\n\t}\n\treturn fmt.Errorf(\"unsupported key: %s format: %s\", src.Key, src.Format)\n}\n\nfunc newActualTypesResolver(enableConvertToType bool) func(map[string]any) error {\n\treturn func(input map[string]any) error {\n\t\tmapper := mapper(input)\n\t\treturn resolver(input, mapper, enableConvertToType)\n\t}\n}\n\n// defaultResolver resolve placeholder in map value,\n// placeholder format in ${key:default}.\nfunc defaultResolver(input map[string]any) error {\n\tmapper := mapper(input)\n\treturn resolver(input, mapper, false)\n}\n\nfunc resolver(input map[string]any, mapper func(name string) string, toType bool) error {\n\tvar resolve func(map[string]any) error","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/go-kratos/kratos/blob/668db92c2c001e9552594ba5a8aede8456af6d7e/config/options.go#L78-L114","documentation":"When the config decoder processes a loaded key it looks up a codec by the key's format (usually derived from the file extension) via encoding.GetCodec; if no codec is registered for that format, decoding fails and the key and format are reported. Extensions without a registered codec package (e.g. toml, ini) trigger it.","triggerScenarios":"Loading a config file whose extension maps to a format with no registered codec — encoding.GetCodec(src.Format) returns nil — such as adding a .toml or .ini file without importing/registering a codec for that format.","commonSituations":"Adding config files in formats the app never imported codecs for; custom extensions like .conf; renaming files to extensions the project does not register.","solutions":["Import (blank) the package that registers the codec for that format so its init runs","Rename the file to an extension with a registered codec (json/yaml)","Register your own codec implementing encoding.Codec and map the extension to it"],"exampleFix":"// before - config.toml loaded, no codec registered for \"toml\"\n\n// after\nimport \"github.com/go-kratos/kratos/v3/encoding\"\n\nfunc init() { encoding.RegisterCodec(\"toml\", &tomlCodec{}) }\n// or blank-import a package that registers the codec","handlingStrategy":"validation","validationCode":"format := strings.TrimPrefix(filepath.Ext(path), \".\")\nif encoding.GetCodec(format) == nil {\n    return fmt.Errorf(\"no codec for %s; register one or rename the file\", path)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Blank-import codec packages for every config extension you ship","Standardize on yaml/json for config files","Validate all source formats at startup and fail fast"],"tags":["config","codec","file-extensions","registration","go"],"backgroundTag":null,"analyzedSha":"668db92c2c001e9552594ba5a8aede8456af6d7e","analyzedAt":"2026-08-16T02:07:20.704Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}