vitessio/vitess · error

unknown keyspace type: %v

Error message

unknown keyspace type: %v

What it means

ParseKeyspaceType failed to map the input string to a topodatapb.KeyspaceType enum value. Keyspace types are NORMAL and SNAPSHOT (case-insensitive). Note the error prints the zero enum value rather than the offending input string, which is confusing, but the cause is always a bad input string.

Source

Thrown at go/vt/topo/topoproto/keyspace.go:31

See the License for the specific language governing permissions and
limitations under the License.
*/

package topoproto

import (
	"fmt"
	"strings"

	topodatapb "vitess.io/vitess/go/vt/proto/topodata"
)

// ParseKeyspaceType parses a string into a KeyspaceType.
func ParseKeyspaceType(param string) (topodatapb.KeyspaceType, error) {
	value, ok := topodatapb.KeyspaceType_value[strings.ToUpper(param)]
	if !ok {
		// default
		return topodatapb.KeyspaceType_NORMAL, fmt.Errorf("unknown keyspace type: %v", value)
	}
	return topodatapb.KeyspaceType(value), nil
}

// KeyspaceTypeString returns the string representation of a KeyspaceType.
func KeyspaceTypeString(kt topodatapb.KeyspaceType) string {
	str, ok := topodatapb.KeyspaceType_name[int32(kt)]
	if !ok {
		return "UNKNOWN"
	}

	return str
}

// KeyspaceTypeLString returns the lowercased string representation of a
// KeyspaceType.
func KeyspaceTypeLString(kt topodatapb.KeyspaceType) string {
	return strings.ToLower(KeyspaceTypeString(kt))

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Pass exactly NORMAL or SNAPSHOT (case-insensitive) as the keyspace type
  2. Remove or fix the empty/misspelled --type value; omit the flag to use the default NORMAL
  3. Check vtctldclient CreateKeyspace --help for accepted values in your version

Example fix

// before
vtctldclient CreateKeyspace --type=duel commerce
// after
vtctldclient CreateKeyspace --type=SNAPSHOT commerce
Defensive patterns

Strategy: validation

Validate before calling

switch strings.ToUpper(kt) {
case "NORMAL", "SNAPSHOT":
    // ok
default:
    return fmt.Errorf("keyspace type must be NORMAL or SNAPSHOT, got %q", kt)
}

Type guard

func isValidKeyspaceType(s string) bool {
    _, ok := topodatapb.KeyspaceType_value[strings.ToUpper(s)]
    return ok
}

Try / catch

kt, err := topoproto.ParseKeyspaceType(typeFlag)
if err != nil {
    return fmt.Errorf("bad --type %q (use NORMAL or SNAPSHOT): %w", typeFlag, err)
}

Prevention

When it happens

Trigger: Calling ParseKeyspaceType (via vtctldclient CreateKeyspace's --type flag or Set) with a string that is not NORMAL or SNAPSHOT after uppercasing, e.g. 'normal2', '' (empty), 'dual'.

Common situations: Omitting/misspelling the --type value on vtctldclient CreateKeyspace; older docs referencing removed keyspace types; empty flag values defaulting unexpectedly.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/b0514fb3970e9975. Report an issue: GitHub.