{"record":{"id":"2f7bb084bc30ebc8","repo":"vitessio/vitess","slug":"could-not-parse-shard-name-q-v","errorCode":null,"errorMessage":"could not parse shard name %q: %+v","messagePattern":"could not parse shard name %q: %\\+v","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtorc/logic/tablet_discovery.go","lineNumber":191,"sourceCode":"\tif len(clustersToWatch) == 0 {\n\t\treturn nil\n\t}\n\n\tfor _, ks := range clustersToWatch {\n\t\tif strings.Contains(ks, \"/\") && !strings.HasSuffix(ks, \"/\") {\n\t\t\t// Validate keyspace/shard parses.\n\t\t\tk, s, err := topoproto.ParseKeyspaceShard(ks)\n\t\t\tif err != nil {\n\t\t\t\tlog.Error(fmt.Sprintf(\"Could not parse keyspace/shard %q: %+v\", ks, err))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif !key.IsValidKeyRange(s) {\n\t\t\t\treturn fmt.Errorf(\"invalid key range %q while parsing clusters to watch\", s)\n\t\t\t}\n\t\t\t// Parse the shard name into key range value.\n\t\t\tkeyRanges, err := key.ParseShardingSpec(s)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"could not parse shard name %q: %+v\", s, err)\n\t\t\t}\n\t\t\tshardsToWatch[k] = append(shardsToWatch[k], keyRanges...)\n\t\t} else {\n\t\t\t// Remove trailing slash if exists.\n\t\t\tks = strings.TrimSuffix(ks, \"/\")\n\t\t\t// We store the entire range of key range if nothing is specified.\n\t\t\tshardsToWatch[ks] = []*topodatapb.KeyRange{key.NewCompleteKeyRange()}\n\t\t}\n\t}\n\n\tif len(shardsToWatch) == 0 {\n\t\tlog.Error(\"No keyspace/shards to watch, watching all keyspaces\")\n\t}\n\treturn nil\n}\n\n// shouldWatchTablet checks if the given tablet is part of the watch list.\nfunc shouldWatchTablet(tablet *topodatapb.Tablet) bool {","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtorc/logic/tablet_discovery.go#L173-L209","documentation":"VTOrc validates each cluster-to-watch entry of the form 'keyspace/shard-spec' before using it. After the keyspace/shard part passes IsValidKeyRange, key.ParseShardingSpec must translate the spec (e.g. '-', '-', '-80,80-') into KeyRanges; if that parsing fails this error is returned and VTOrc cannot build its shardsToWatch map, aborting discovery/initialization.","triggerScenarios":"Calling initializeShardsToWatch (via OpenTabletDiscovery, RefreshAllKeyspaces/RefreshAllShards, or tests) with a --clusters_to_watch entry whose shard portion is not a valid sharding spec — e.g. 'ks/badshard', 'ks/-abc', 'ks/1-2-3', or an unparseable numeric range.","commonSituations":"Typo in the clusters-to-watch flag/config; copying a shard name from MySQL rather than Vitess naming conventions; using a keyspace-only entry with a stray suffix; a shard that was split/renamed so the old spec no longer parses.","solutions":["Fix the shard spec in the clusters_to_watch config/flag to use valid Vitess shard syntax ('-', '-', '-80', '80-', 'c0-', etc.)","Verify with key.ParseShardingSpec semantics: entries must be '-' or N-M / -N / N- numeric ranges","If you only want all shards, use the keyspace with an empty shard portion so the whole keyspace is watched","Validate the value offline (e.g. in a Go test calling key.IsValidKeyRange and key.ParseShardingSpec) before deploying"],"exampleFix":"// before\nclustersToWatch = []string{\"commerce/primary\"}\n// after\nclustersToWatch = []string{\"commerce/-\"}","handlingStrategy":"validation","validationCode":"if !key.IsValidKeyRange(spec) || !(func(){ _, err := key.ParseShardingSpec(spec); return err == nil })() {\n    return fmt.Errorf(\"invalid shard spec %q\", spec)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use '-' or explicit numeric ranges for shard specs","Lint clusters_to_watch values at deploy time","Test configs with key.ParseShardingSpec before rollout"],"tags":["vtorc","config","shard-parsing"],"backgroundTag":"invalid-shard-name","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}