{"record":{"id":"a8589eeb347d4aec","repo":"ipfs/kubo","slug":"prefix-field-was-missing-or-not-a-string","errorCode":null,"errorMessage":"'prefix' field was missing or not a string","messagePattern":"'prefix' field was missing or not a string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/fsrepo/datastores.go","lineNumber":231,"sourceCode":"\ntype measureDatastoreConfig struct {\n\tchild  DatastoreConfig\n\tprefix string\n}\n\n// MeasureDatastoreConfig returns a measure DatastoreConfig from a spec.\nfunc MeasureDatastoreConfig(params map[string]any) (DatastoreConfig, error) {\n\tchildField, ok := params[\"child\"].(map[string]any)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"'child' field is missing or not a map\")\n\t}\n\tchild, err := AnyDatastoreConfig(childField)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tprefix, ok := params[\"prefix\"].(string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"'prefix' field was missing or not a string\")\n\t}\n\treturn &measureDatastoreConfig{child, prefix}, nil\n}\n\nfunc (c *measureDatastoreConfig) DiskSpec() DiskSpec {\n\treturn c.child.DiskSpec()\n}\n\nfunc (c measureDatastoreConfig) Create(path string) (repo.Datastore, error) {\n\tchild, err := c.child.Create(path)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn measure.New(c.prefix, child), nil\n}\n","sourceCodeStart":213,"sourceCodeEnd":247,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/repo/fsrepo/datastores.go#L213-L247","documentation":"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.","triggerScenarios":"Calling MeasureDatastoreConfig with a valid \"child\" but where params[\"prefix\"] is absent, nil, or a non-string (e.g. int).","commonSituations":"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.","solutions":["Add a string 'prefix' field to the measure datastore entry in Datastore.Spec","Example: {\"type\":\"measure\",\"prefix\":\"flatfs.datastore\",\"child\":{...}}"],"exampleFix":"// before\nspec := map[string]any{\"type\": \"measure\", \"child\": childSpec}\n// after\nspec := map[string]any{\"type\": \"measure\", \"prefix\": \"disk\", \"child\": childSpec}","handlingStrategy":"validation","validationCode":"p, ok := params[\"prefix\"].(string)\nif !ok || p == \"\" { /* add prefix before calling */ }","typeGuard":"func measurePrefix(params map[string]any) (string, bool) {\n\tp, ok := params[\"prefix\"].(string)\n\treturn p, ok && p != \"\"\n}","tryCatchPattern":"ds, err := fsrepo.MeasureDatastoreConfig(spec)\nif err != nil {\n\tif strings.Contains(err.Error(), \"'prefix' field\") {\n\t\treturn fmt.Errorf(\"measure spec requires a prefix: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["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"],"tags":["datastore","config","measure","validation","go"],"backgroundTag":"datastore-spec-invalid","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"}