ipfs/kubo · error
failure to decode config: %w
Error message
failure to decode config: %w
What it means
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.
Source
Thrown at config/config.go:130
return []byte(strings.Trim(s, "\n")), nil
}
return Marshal(value)
}
// Marshal configuration with JSON.
func Marshal(value any) ([]byte, error) {
// need to prettyprint, hence MarshalIndent, instead of Encoder
return json.MarshalIndent(value, "", " ")
}
func FromMap(v map[string]any) (*Config, error) {
buf := new(bytes.Buffer)
if err := json.NewEncoder(buf).Encode(v); err != nil {
return nil, err
}
var conf Config
if err := json.NewDecoder(buf).Decode(&conf); err != nil {
return nil, fmt.Errorf("failure to decode config: %w", err)
}
return &conf, nil
}
func ToMap(conf *Config) (map[string]any, error) {
buf := new(bytes.Buffer)
if err := json.NewEncoder(buf).Encode(conf); err != nil {
return nil, err
}
var m map[string]any
if err := json.NewDecoder(buf).Decode(&m); err != nil {
return nil, fmt.Errorf("failure to decode config: %w", err)
}
return m, nil
}
// Convert config to a map, without using encoding/json, since
// zero/empty/'omitempty' fields are excluded by encoding/json duringView on GitHub (pinned to 329838acdf)
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)
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at config/config.go:130 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/c7cda1ae40de2273.
Report an issue: GitHub.