ipfs/kubo · error
'type' field missing or not a string
Error message
'type' field missing or not a string
What it means
AnyDatastoreConfig builds a DatastoreConfig from a JSON-style spec map by first reading params["type"]. If the key is absent or its value does not assert to string, the spec is unusable (the datastore registry is keyed by type name), so the function returns this error instead of guessing.
Source
Thrown at repo/fsrepo/datastores.go:81
}
}
func AddDatastoreConfigHandler(name string, dsc ConfigFromMap) error {
_, ok := datastores[name]
if ok {
return fmt.Errorf("already have a datastore named %q", name)
}
datastores[name] = dsc
return nil
}
// AnyDatastoreConfig returns a DatastoreConfig from a spec based on
// the "type" parameter.
func AnyDatastoreConfig(params map[string]any) (DatastoreConfig, error) {
which, ok := params["type"].(string)
if !ok {
return nil, fmt.Errorf("'type' field missing or not a string")
}
fun, ok := datastores[which]
if !ok {
return nil, fmt.Errorf("unknown datastore type: %s", which)
}
return fun(params)
}
type mountDatastoreConfig struct {
mounts []premount
}
type premount struct {
ds DatastoreConfig
prefix ds.Key
}
// MountDatastoreConfig returns a mount DatastoreConfig from a spec.View on GitHub (pinned to 329838acdf)
Solutions
- Add a "type" key with the datastore name (e.g. "mounts", "flatfs", "levelds", "measure", "log") to the spec map
- Print/inspect the spec map and fix JSON parsing so "type" survives as a string, e.g. use json.Unmarshal into map[string]any
- If the spec came from a migration or tooling, regenerate it with a template that includes "type"
Example fix
// before
spec := map[string]any{"path": "/datastore"}
ds, err := fsrepo.AnyDatastoreConfig(spec) // error
// after
spec := map[string]any{"type": "flatfs", "path": "/datastore"}
ds, err := fsrepo.AnyDatastoreConfig(spec) Defensive patterns
Strategy: validation
Validate before calling
func validSpec(params map[string]any) bool {
t, ok := params["type"].(string)
return ok && t != ""
}
if !validSpec(spec) { /* fix spec before calling */ } Type guard
func hasStringType(params map[string]any) (string, bool) {
t, ok := params["type"].(string)
return t, ok
} Try / catch
ds, err := fsrepo.AnyDatastoreConfig(spec)
if err != nil {
if strings.Contains(err.Error(), "'type' field missing") {
// log spec keys and abort init
}
return fmt.Errorf("invalid datastore spec %v: %w", spec, err)
} Prevention
- Always include a "type" string in every datastore spec map
- Unmarshal config JSON with map[string]any so "type" arrives as a string
- Validate specs against the registered datastore names before use
When it happens
Trigger: Calling AnyDatastoreConfig(params) where params is a map[string]any parsed from a Datastore spec that lacks a "type" key, or where params["type"] is a non-string value (e.g. int, nil, nested map from malformed JSON).
Common situations: Hand-edited or programmatically generated datastore spec in the repo config missing the "type" field; JSON unmarshalled into the wrong shape; a mount entry forgetting its type; config migration or templating tools dropping the field.
Related errors
- creating datastore config for %s: %w
- unknown datastore type: %s
- 'mounts' field is missing or not an array
- expected map for mountpoint
- no 'mountpoint' on mount
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/5f6df0c717112e1b.
Report an issue: GitHub.