{"record":{"id":"c7cda1ae40de2273","repo":"ipfs/kubo","slug":"failure-to-decode-config-w","errorCode":null,"errorMessage":"failure to decode config: %w","messagePattern":"failure to decode config: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/config.go","lineNumber":130,"sourceCode":"\t\treturn []byte(strings.Trim(s, \"\\n\")), nil\n\t}\n\treturn Marshal(value)\n}\n\n// Marshal configuration with JSON.\nfunc Marshal(value any) ([]byte, error) {\n\t// need to prettyprint, hence MarshalIndent, instead of Encoder\n\treturn json.MarshalIndent(value, \"\", \"  \")\n}\n\nfunc FromMap(v map[string]any) (*Config, error) {\n\tbuf := new(bytes.Buffer)\n\tif err := json.NewEncoder(buf).Encode(v); err != nil {\n\t\treturn nil, err\n\t}\n\tvar conf Config\n\tif err := json.NewDecoder(buf).Decode(&conf); err != nil {\n\t\treturn nil, fmt.Errorf(\"failure to decode config: %w\", err)\n\t}\n\treturn &conf, nil\n}\n\nfunc ToMap(conf *Config) (map[string]any, error) {\n\tbuf := new(bytes.Buffer)\n\tif err := json.NewEncoder(buf).Encode(conf); err != nil {\n\t\treturn nil, err\n\t}\n\tvar m map[string]any\n\tif err := json.NewDecoder(buf).Decode(&m); err != nil {\n\t\treturn nil, fmt.Errorf(\"failure to decode config: %w\", err)\n\t}\n\treturn m, nil\n}\n\n// Convert config to a map, without using encoding/json, since\n// zero/empty/'omitempty' fields are excluded by encoding/json during","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/config/config.go#L112-L148","documentation":"FromMap re-encodes a generic map through JSON into a typed Config, and the decode step failed. This means the map's shape or value types do not match the config schema (unknown/wrong-typed fields), e.g. when SetConfigKey writes a value the Config struct cannot accept. %w carries the json.Decoder error.","triggerScenarios":"Thrown at config/config.go:130 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the key path and value type against docs/config.md and retry the config write","Inspect the wrapped JSON error for the offending field name","Fix the stored config file if it is already corrupt (restore a backup or re-init)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}