{"record":{"id":"fe9a49a460a9270d","repo":"ipfs/kubo","slug":"name-field-was-missing-or-not-a-string","errorCode":null,"errorMessage":"'name' field was missing or not a string","messagePattern":"'name' field was missing or not a string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/fsrepo/datastores.go","lineNumber":197,"sourceCode":"\ntype logDatastoreConfig struct {\n\tchild DatastoreConfig\n\tname  string\n}\n\n// LogDatastoreConfig returns a log DatastoreConfig from a spec.\nfunc LogDatastoreConfig(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\tname, ok := params[\"name\"].(string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"'name' field was missing or not a string\")\n\t}\n\treturn &logDatastoreConfig{child, name}, nil\n}\n\nfunc (c *logDatastoreConfig) 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 ds.NewLogDatastore(child, c.name), nil\n}\n\nfunc (c *logDatastoreConfig) DiskSpec() DiskSpec {\n\treturn c.child.DiskSpec()\n}\n\ntype measureDatastoreConfig struct {\n\tchild  DatastoreConfig","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/repo/fsrepo/datastores.go#L179-L215","documentation":"LogDatastoreConfig reads params[\"name\"] to label log events emitted by the wrapping datastore. When \"name\" is absent or not a string, the wrapper cannot be identified in logs, so the error is returned.","triggerScenarios":"Calling LogDatastoreConfig with a valid \"child\" but where params[\"name\"] is missing, nil, or a non-string value (e.g. a number).","commonSituations":"Spec of type \"log\" with \"child\" filled in but the \"name\" field forgotten; name provided as a non-string in programmatically built maps.","solutions":["Add \"name\" as a string to the log datastore spec (e.g. \"name\": \"datastore-log\")","Coerce or fix the value so it is a Go string in the spec map"],"exampleFix":"// before\nspec := map[string]any{\"type\": \"log\", \"child\": childSpec}\n// after\nspec := map[string]any{\"type\": \"log\", \"name\": \"dslog\", \"child\": childSpec}","handlingStrategy":"validation","validationCode":"n, ok := params[\"name\"].(string)\nif !ok || n == \"\" { /* add name before calling */ }","typeGuard":"func logName(params map[string]any) (string, bool) {\n\tn, ok := params[\"name\"].(string)\n\treturn n, ok && n != \"\"\n}","tryCatchPattern":"ds, err := fsrepo.LogDatastoreConfig(spec)\nif err != nil {\n\tif strings.Contains(err.Error(), \"'name' field\") {\n\t\treturn fmt.Errorf(\"log spec requires a name: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Always set \"name\" as a string in log datastore specs","Use a descriptive, stable name since it labels emitted log events","Type-check programmatically built maps before calling"],"tags":["datastore","config","log","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"}