micro/go-micro · error
unsupported format
Error message
unsupported format
What it means
The JSON config reader only accepts changesets whose Format field is exactly "json". Values checks ch.Format != "json" and returns "unsupported format" otherwise. Each go-micro reader (json, yaml, etc.) handles only its own format, so a changeset produced by a different source format must be routed to the matching reader.
Source
Thrown at config/reader/json/json.go:67
}
cs := &source.ChangeSet{
Timestamp: time.Now(),
Data: b,
Source: "json",
Format: j.json.String(),
}
cs.Checksum = cs.Sum()
return cs, nil
}
func (j *jsonReader) Values(ch *source.ChangeSet) (reader.Values, error) {
if ch == nil {
return nil, errors.New("changeset is nil")
}
if ch.Format != "json" {
return nil, errors.New("unsupported format")
}
return newValues(ch)
}
func (j *jsonReader) String() string {
return "json"
}
// NewReader creates a json reader.
func NewReader(opts ...reader.Option) reader.Reader {
options := reader.NewOptions(opts...)
return &jsonReader{
json: json.NewEncoder(),
opts: options,
}
}
View on GitHub (pinned to 24529f1404)
Solutions
- Ensure ChangeSet.Format is set to "json" for changesets passed to the json reader (fix the source if it leaves Format empty).
- Use the reader matching the file format: yaml reader for YAML files, toml reader for TOML, etc.
- Verify config source options (e.g. file.Extension / format option) match the actual file's format.
- If you must accept multiple formats, dispatch on ch.Format to the appropriate reader instead of hardcoding json.
Example fix
// before // yaml file loaded with json reader conf := json.New() v, _ := conf.Values(yamlChangeSet) // unsupported format // after conf := yaml.New() v, err := conf.Values(yamlChangeSet)
Defensive patterns
Strategy: validation
Validate before calling
if cs == nil || cs.Format != "json" {
return fmt.Errorf("json reader requires Format=json, got %q", cs.GetFormat())
}
vals, err := rdr.Values(cs) Type guard
func isJSONChangeSet(ch *source.ChangeSet) bool { return ch != nil && ch.Format == "json" } Prevention
- Match the reader to the file format (json reader for .json, yaml reader for .yaml).
- Ensure custom sources always set ChangeSet.Format.
- Dispatch on Format when supporting multiple config formats.
- Verify config source extension/format options after changing config files.
When it happens
Trigger: Passing a *source.ChangeSet with Format "yaml", "toml", "hcl", or "" (unset) to jsonReader.Values — e.g. a YAML source's output fed into the JSON reader, or a custom source that forgot to set ChangeSet.Format.
Common situations: Loading a .yaml file but using the json reader in the config options; a custom source that returns a changeset without setting Format; changing a config file's format on disk without updating the reader codec selection.
Related errors
AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01).
Data as JSON: /api/errors/fce44c8b76671a0b.
Report an issue: GitHub.