{"record":{"id":"d491cc8924adbb76","repo":"vitessio/vitess","slug":"no-shards-found-in-keyspace-s","errorCode":null,"errorMessage":"no shards found in keyspace %s","messagePattern":"no shards found in keyspace (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/grpcvtctldserver/server.go","lineNumber":4901,"sourceCode":"\tdefer panicHandler(&err)\n\n\tspan.Annotate(\"keyspace\", req.Keyspace)\n\tspan.Annotate(\"shards\", req.Shards)\n\n\tvar shards []string\n\tif len(req.Shards) != 0 {\n\t\t// If the user has specified a list of specific shards, we'll use that.\n\t\tshards = req.Shards\n\t} else {\n\t\t// Validate all of the shards.\n\t\tshards, err = s.ts.GetShardNames(ctx, req.Keyspace)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\tif len(shards) == 0 {\n\t\treturn nil, fmt.Errorf(\"no shards found in keyspace %s\", req.Keyspace)\n\t}\n\tsort.Strings(shards)\n\n\t// Find the reference permissions using the first shard's primary.\n\tsi, err := s.ts.GetShard(ctx, req.Keyspace, shards[0])\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif !si.HasPrimary() {\n\t\treturn nil, fmt.Errorf(\"no primary tablet in shard %s/%s\", req.Keyspace, shards[0])\n\t}\n\treferenceAlias := si.PrimaryAlias\n\tlog.Info(\"Gathering permissions for reference primary \" + topoproto.TabletAliasString(referenceAlias))\n\tpres, err := s.GetPermissions(ctx, &vtctldatapb.GetPermissionsRequest{\n\t\tTabletAlias: si.PrimaryAlias,\n\t})\n\tif err != nil {\n\t\treturn nil, err","sourceCodeStart":4883,"sourceCodeEnd":4919,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/grpcvtctldserver/server.go#L4883-L4919","documentation":"Returned by CopyShardPermissions/CopySchemaShard-style flows when the source keyspace contains no shards. The operation needs at least one shard from which to pick a reference primary tablet, so it fails early.","triggerScenarios":"Calling the copy-permissions/copy-schema-shard vtctld RPC against a keyspace whose shard list is empty — e.g. a freshly created keyspace with no tablets yet, or a typo'd keyspace name.","commonSituations":"Typo in the keyspace name resolving to an empty/fresh keyspace; running the copy before the source keyspace has been initialized with tablets; source shards were all removed after resharding completed.","solutions":["Verify the keyspace name is spelled correctly","Ensure the source keyspace has shards/tablets (`vtctldclient GetSrvKeyspace` or `GetKeyspace`)","Initialize the keyspace with tablets before copying permissions/schema","Re-run the copy after resharding cleanup has restored shards, or copy from the original keyspace"],"exampleFix":"// before\nif len(shards) == 0 {\n    return nil, fmt.Errorf(\"no shards found in keyspace %s\", req.Keyspace)\n}\n// after\nif len(shards) == 0 {\n    return nil, vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, \"no shards found in keyspace %s; ensure the keyspace has tablets before copying\", req.Keyspace)\n}","handlingStrategy":"validation","validationCode":"srvKeyspace, err := topoServer.GetSrvKeyspace(ctx, cell, keyspace)\nif err != nil || len(srvKeyspace.Partitions) == 0 { /* keyspace empty; abort */ }","typeGuard":null,"tryCatchPattern":"try {\n  await client.copySchemaShard(sourceKeyspace, shard)\n} catch (e) {\n  if (String(e).includes('no shards found in keyspace')) {\n    // check spelling / initialize tablets in source keyspace\n  } else { throw e }\n}","preventionTips":["Double-check keyspace spelling before copy operations","Ensure the source keyspace has tablets/shards before copying schema/permissions","Do not run copy flows after all source shards were removed by resharding cleanup","Use GetSrvKeyspace as a preflight to confirm the keyspace is populated"],"tags":["topology","keyspace","shard","precondition"],"backgroundTag":"empty-keyspace","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}