{"record":{"id":"da46689e5c3b9439","repo":"vitessio/vitess","slug":"action-initshardprimary-requires-keyspace-shard","errorCode":null,"errorMessage":"action InitShardPrimary requires <keyspace/shard> <tablet alias>","messagePattern":"action InitShardPrimary requires <keyspace/shard> <tablet alias>","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/reparent.go","lineNumber":99,"sourceCode":"\ttabletAlias, err := topoproto.ParseTabletAlias(subFlags.Arg(0))\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn wr.ReparentTablet(ctx, tabletAlias)\n}\n\nfunc commandInitShardPrimary(ctx context.Context, wr *wrangler.Wrangler, subFlags *pflag.FlagSet, args []string) error {\n\tif mysqlctl.DisableActiveReparents {\n\t\treturn errors.New(\"active reparent commands disabled (unset the --disable-active-reparents flag to enable)\")\n\t}\n\n\tforce := subFlags.Bool(\"force\", false, \"will force the reparent even if the provided tablet is not writable or the shard primary\")\n\twaitReplicasTimeout := subFlags.Duration(\"wait_replicas_timeout\", topo.RemoteOperationTimeout, \"time to wait for replicas to catch up in reparenting\")\n\tif err := subFlags.Parse(args); err != nil {\n\t\treturn err\n\t}\n\tif subFlags.NArg() != 2 {\n\t\treturn errors.New(\"action InitShardPrimary requires <keyspace/shard> <tablet alias>\")\n\t}\n\tkeyspace, shard, err := topoproto.ParseKeyspaceShard(subFlags.Arg(0))\n\tif err != nil {\n\t\treturn err\n\t}\n\ttabletAlias, err := topoproto.ParseTabletAlias(subFlags.Arg(1))\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn wr.InitShardPrimary(ctx, keyspace, shard, tabletAlias, *force, *waitReplicasTimeout)\n}\n\nfunc commandPlannedReparentShard(ctx context.Context, wr *wrangler.Wrangler, subFlags *pflag.FlagSet, args []string) error {\n\tif mysqlctl.DisableActiveReparents {\n\t\treturn errors.New(\"active reparent commands disabled (unset the --disable-active-reparents flag to enable)\")\n\t}\n\n\twaitReplicasTimeout := subFlags.Duration(\"wait_replicas_timeout\", topo.RemoteOperationTimeout, \"time to wait for replicas to catch up on replication before and after reparenting\")","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/reparent.go#L81-L117","documentation":"commandInitShardPrimary requires exactly two positional arguments: the keyspace/shard and the tablet alias to be initialized as primary. Any other count yields this usage error before parsing, mirroring the ReparentTablet argument check but with the shard-qualified form.","triggerScenarios":"Running `vtctldclient InitShardPrimary` with zero, one, or three-plus positional args — e.g. omitting the shard, or passing only the tablet alias as with ReparentTablet.","commonSituations":"Confusing InitShardPrimary's two-arg form with ReparentTablet's one-arg form; empty shell variables dropping an argument.","solutions":["Invoke with exactly two arguments: `vtctldclient InitShardPrimary <keyspace/shard> <tablet alias>`","Add --force if the tablet must be initialized as primary even when it is not currently writable or is already primary","Validate shell variables so both arguments are non-empty before invocation"],"exampleFix":"// before\nvtctldclient InitShardPrimary zone1-0000000100\n// after\nvtctldclient InitShardPrimary commerce/0 zone1-0000000100","handlingStrategy":"validation","validationCode":"args=(\"$@\"); if [ ${#args[@]} -ne 2 ]; then\n  echo \"usage: vtctldclient InitShardPrimary <keyspace/shard> <tablet alias>\" >&2; exit 2\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass keyspace/shard and tablet alias in that order","Validate keyspace/shard with topoproto.ParseKeyspaceShard-style formatting before invoking","Distinguish from ReparentTablet's single-argument form in scripts and docs"],"tags":["reparenting","init-primary","cli","argument-validation"],"backgroundTag":"invalid-cli-argument","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}