{"record":{"id":"a3f21755357488d5","repo":"zincsearch/zincsearch","slug":"index-name-should-be-not-empty","errorCode":null,"errorMessage":"index.name should be not empty","messagePattern":"index\\.name should be not empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/handlers/index/create.go","lineNumber":105,"sourceCode":"\t\tzutils.GinRenderJSON(c, http.StatusBadRequest, meta.HTTPResponseError{Error: err.Error()})\n\t\treturn\n\t}\n\n\tzutils.GinRenderJSON(c, http.StatusOK, gin.H{\n\t\t\"acknowledged\":        true,\n\t\t\"shards_acknowledged\": true,\n\t\t\"index\":               newIndex.Name,\n\t})\n}\n\nfunc CreateIndexWorker(newIndex *meta.IndexSimple, indexName string) error {\n\tnewIndex.StorageType = \"disk\"\n\tif newIndex.Name == \"\" && indexName != \"\" {\n\t\tnewIndex.Name = indexName\n\t}\n\n\tif newIndex.Name == \"\" {\n\t\treturn errors.New(\"index.name should be not empty\")\n\t}\n\n\tif _, ok := core.GetIndex(newIndex.Name); ok {\n\t\treturn errors.New(\"index [\" + newIndex.Name + \"] already exists\")\n\t}\n\n\tif newIndex.Settings == nil {\n\t\tnewIndex.Settings = new(meta.IndexSettings)\n\t}\n\tanalyzers, err := zincanalysis.RequestAnalyzer(newIndex.Settings.Analysis)\n\tif err != nil {\n\t\treturn errors.New(err.Error())\n\t}\n\n\tmappings, err := mappings.Request(analyzers, newIndex.Mappings)\n\tif err != nil {\n\t\treturn errors.New(err.Error())\n\t}","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/zincsearch/zincsearch/blob/dd2f8afd6562d4d52c41b2c5d312280e684a25ba/pkg/handlers/index/create.go#L87-L123","documentation":"CreateIndexWorker validates that an index has a non-empty name before creating it in the core index store. If the parsed request body (newIndex.Name) is empty and no index name was supplied out-of-band (URL path or query param indexName), the handler refuses to create an index. This guards against nameless indices corrupting the in-memory index map.","triggerScenarios":"Calling POST /api/index with a JSON body that omits the \"name\" field (or sets it to \"\"), without providing an index name in the request path/query parameter.","commonSituations":"Copy-pasted curl bodies missing the name field; clients that send only settings/mappings; API wrappers that strip unknown JSON fields; using an endpoint variant where the name is expected in the URL but only the body was sent.","solutions":["Add a non-empty \"name\" field to the index creation JSON body","Pass the index name in the request path/query parameter so indexName fills it in","Verify your HTTP client is not dropping the name field during JSON serialization"],"exampleFix":"// before\ncurl -X POST http://localhost:4080/api/index -d '{\"storage_type\":\"disk\"}'\n// after\ncurl -X POST http://localhost:4080/api/index -d '{\"name\":\"my-index\",\"storage_type\":\"disk\"}'","handlingStrategy":"validation","validationCode":"const body = JSON.parse(requestBody);\nif (!body.name || typeof body.name !== 'string' || body.name.trim() === '') {\n  throw new Error('Index creation requires a non-empty \"name\" field');\n}","typeGuard":"function hasValidIndexName(b) {\n  return typeof b === 'object' && b !== null &&\n    typeof b.name === 'string' && b.name.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["Always include name in the index creation payload","Send the index name in the URL path when using path-based endpoints","Add a client-side schema check before calling the create-index API","Log the serialized body when creation fails to catch dropped fields"],"tags":["index","validation","api"],"backgroundTag":"missing-required-argument","analyzedSha":"dd2f8afd6562d4d52c41b2c5d312280e684a25ba","analyzedAt":"2026-09-03T00:22:38.551Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}