{"record":{"id":"8425d5e686bc54f0","repo":"vitessio/vitess","slug":"keyspace-is-required","errorCode":null,"errorMessage":"keyspace is required","messagePattern":"keyspace is required","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctld/api.go","lineNumber":245,"sourceCode":"\t})\n\n\thandleCollection(\"keyspace\", func(r *http.Request) (any, error) {\n\t\t// Valid requests: api/keyspace/my_ks/tablets (all shards)\n\t\t// Valid requests: api/keyspace/my_ks/tablets/-80 (specific shard)\n\t\titemPath := getItemPath(r.URL.Path)\n\t\tparts := strings.SplitN(itemPath, \"/\", 3)\n\n\t\tmalformedRequestError := fmt.Errorf(\"invalid keyspace path: %q  expected path: /keyspace/<keyspace>/tablets or /keyspace/<keyspace>/tablets/<shard>\", itemPath)\n\t\tif len(parts) < 2 {\n\t\t\treturn nil, malformedRequestError\n\t\t}\n\t\tif parts[1] != \"tablets\" {\n\t\t\treturn nil, malformedRequestError\n\t\t}\n\n\t\tkeyspace := parts[0]\n\t\tif keyspace == \"\" {\n\t\t\treturn nil, errors.New(\"keyspace is required\")\n\t\t}\n\t\tvar shardNames []string\n\t\tif len(parts) > 2 && parts[2] != \"\" {\n\t\t\tshardNames = []string{parts[2]}\n\t\t} else {\n\t\t\tvar err error\n\t\t\tshardNames, err = ts.GetShardNames(ctx, keyspace)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t}\n\n\t\tif err := r.ParseForm(); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tcell := r.FormValue(\"cell\")\n\t\tcells := r.FormValue(\"cells\")\n\t\tfilterCells := []string{} // empty == all cells","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctld/api.go#L227-L263","documentation":"The shards HTTP API routes requests of the form /api/<keyspace>/tablets[/<shard>]. If the first path segment (the keyspace) is empty the handler rejects the request with 'keyspace is required' before resolving shards. It is a request-validation error produced when the URL path is malformed.","triggerScenarios":"Requesting a path like /api//tablets or /api/tablets where the keyspace segment is empty; programmatically built URLs with an empty keyspace variable.","commonSituations":"Template/format-string bugs where the keyspace variable was not interpolated; clients migrated from vtctl where a default keyspace was assumed; truncated URLs.","solutions":["Build the URL with the keyspace: GET /api/<keyspace>/tablets (optionally /api/<keyspace>/tablets/<shard>).","Validate the keyspace value is non-empty before constructing the URL in your client code.","Check upstream data feeding the script — the keyspace may be missing because of an earlier failed API call."],"exampleFix":"// before\ncurl http://localhost:15000/api//tablets\n// after\ncurl http://localhost:15000/api/commerce/tablets","handlingStrategy":"validation","validationCode":"if keyspace == \"\" {\n    return fmt.Errorf(\"cannot build tablets URL: keyspace is required\")\n}\npath := fmt.Sprintf(\"/api/%s/tablets\", keyspace)","typeGuard":null,"tryCatchPattern":"resp, err := http.Get(base + path)\nif err != nil || resp.StatusCode == http.StatusBadRequest {\n    // 'keyspace is required' - check the keyspace segment of the URL\n}","preventionTips":["Validate keyspace non-empty before constructing API URLs.","Use url.PathEscape for path segments."],"tags":["http-api","vtctld","keyspace","url-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}