{"record":{"id":"8432e80760403fec","repo":"ipfs/kubo","slug":"failure-to-encode-config-w","errorCode":null,"errorMessage":"failure to encode config: %w","messagePattern":"failure to encode config: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/config.go","lineNumber":218,"sourceCode":"\t\t}\n\t\treturn result\n\n\tdefault:\n\t\t// For basic types (int, string, etc.), just return the value\n\t\tif v.CanInterface() {\n\t\t\treturn v.Interface()\n\t\t}\n\t\treturn nil\n\t}\n}\n\n// Clone copies the config. Use when updating.\nfunc (c *Config) Clone() (*Config, error) {\n\tvar newConfig Config\n\tvar buf bytes.Buffer\n\n\tif err := json.NewEncoder(&buf).Encode(c); err != nil {\n\t\treturn nil, fmt.Errorf(\"failure to encode config: %w\", err)\n\t}\n\n\tif err := json.NewDecoder(&buf).Decode(&newConfig); err != nil {\n\t\treturn nil, fmt.Errorf(\"failure to decode config: %w\", err)\n\t}\n\n\treturn &newConfig, nil\n}\n\n// Check if the provided key is present in the structure.\nfunc CheckKey(key string) error {\n\tconf := Config{}\n\n\t// Convert an empty config to a map without JSON.\n\tcursor := ReflectToMap(&conf)\n\n\t// Parse the key and verify it's presence in the map.\n\tvar ok bool","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/config/config.go#L200-L236","documentation":"Config.Clone serializes the Config through JSON to deep-copy it, and the encode step failed. JSON encoding of the config only fails if a field holds a value that cannot marshal (unsupported type or a value triggering a Marshaler error); a normal on-disk config never triggers this. %w is the underlying json.Encoder error.","triggerScenarios":"Thrown at config/config.go:218 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped error to find which field fails to marshal","Restore or re-create a valid config file and retry the operation that clones it"],"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"}