ipfs/kubo · error
'prefix' field was missing or not a string
Error message
'prefix' field was missing or not a string
What it means
MeasureDatastoreConfig was asked to build a 'measure' datastore spec whose 'child' parsed fine but the spec has no (or a non-string) 'prefix' field; the measure wrapper needs the prefix to namespace its metrics.
Source
Thrown at repo/fsrepo/datastores.go:231
type measureDatastoreConfig struct {
child DatastoreConfig
prefix string
}
// MeasureDatastoreConfig returns a measure DatastoreConfig from a spec.
func MeasureDatastoreConfig(params map[string]any) (DatastoreConfig, error) {
childField, ok := params["child"].(map[string]any)
if !ok {
return nil, fmt.Errorf("'child' field is missing or not a map")
}
child, err := AnyDatastoreConfig(childField)
if err != nil {
return nil, err
}
prefix, ok := params["prefix"].(string)
if !ok {
return nil, fmt.Errorf("'prefix' field was missing or not a string")
}
return &measureDatastoreConfig{child, prefix}, nil
}
func (c *measureDatastoreConfig) DiskSpec() DiskSpec {
return c.child.DiskSpec()
}
func (c measureDatastoreConfig) Create(path string) (repo.Datastore, error) {
child, err := c.child.Create(path)
if err != nil {
return nil, err
}
return measure.New(c.prefix, child), nil
}
View on GitHub (pinned to 329838acdf)
Solutions
- Add a string 'prefix' field to the measure datastore entry in Datastore.Spec
- Example: {"type":"measure","prefix":"flatfs.datastore","child":{...}}
Example fix
// before
spec := map[string]any{"type": "measure", "child": childSpec}
// after
spec := map[string]any{"type": "measure", "prefix": "disk", "child": childSpec} Defensive patterns
Strategy: validation
Validate before calling
p, ok := params["prefix"].(string)
if !ok || p == "" { /* add prefix before calling */ } Type guard
func measurePrefix(params map[string]any) (string, bool) {
p, ok := params["prefix"].(string)
return p, ok && p != ""
} Try / catch
ds, err := fsrepo.MeasureDatastoreConfig(spec)
if err != nil {
if strings.Contains(err.Error(), "'prefix' field") {
return fmt.Errorf("measure spec requires a prefix: %w", err)
}
return err
} Prevention
- Always set "prefix" as a string in measure datastore specs
- Use a metric-friendly prefix name
- Validate spec fields with a helper before constructing wrappers
When it happens
Trigger: Calling MeasureDatastoreConfig with a valid "child" but where params["prefix"] is absent, nil, or a non-string (e.g. int).
Common situations: Spec of type "measure" where "prefix" was forgotten after adding "child"; prefix supplied as a non-string in hand-built maps; renamed key in generated specs.
Related errors
- 'mounts' field is missing or not an array
- expected map for mountpoint
- no 'mountpoint' on mount
- 'name' field was missing or not a string
- Provide.DHT.KeystoreBatchSize must be positive, got %d
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/a8589eeb347d4aec.
Report an issue: GitHub.