vitessio/vitess · error · errors.ErrInvalidRequest

%w: keyspace name is required

Error message

%w: keyspace name is required

What it means

CreateKeyspace requires req.Name to be a non-empty keyspace name; when it is empty the function returns errors.ErrInvalidRequest wrapped with this message. A keyspace cannot be created in the topo server without a name, so the request is rejected before acquiring the topo RW pool or calling vtctld.

Source

Thrown at go/vt/vtadmin/cluster/cluster.go:433

	span.Annotate("uuid", req.Uuid)

	return c.Vtctld.CompleteSchemaMigration(ctx, req)
}

// CreateKeyspace creates a keyspace in the given cluster, proxying a
// CreateKeyspaceRequest to a vtctld in that cluster.
func (c *Cluster) CreateKeyspace(ctx context.Context, req *vtctldatapb.CreateKeyspaceRequest) (*vtadminpb.Keyspace, error) {
	span, ctx := trace.NewSpan(ctx, "Cluster.CreateKeyspace")
	defer span.Finish()

	AnnotateSpan(c, span)

	if req == nil {
		return nil, fmt.Errorf("%w: request cannot be nil", errors.ErrInvalidRequest)
	}

	if req.Name == "" {
		return nil, fmt.Errorf("%w: keyspace name is required", errors.ErrInvalidRequest)
	}

	span.Annotate("keyspace", req.Name)

	if err := c.topoRWPool.Acquire(ctx); err != nil {
		return nil, fmt.Errorf("CreateKeyspace(%+v) failed to acquire topoRWPool: %w", req, err)
	}
	defer c.topoRWPool.Release()

	resp, err := c.Vtctld.CreateKeyspace(ctx, req)
	if err != nil {
		return nil, err
	}

	return &vtadminpb.Keyspace{
		Cluster:  c.ToProto(),
		Keyspace: resp.Keyspace,
		Shards:   map[string]*vtctldatapb.Shard{},

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Set req.Name to the desired keyspace name before calling CreateKeyspace.
  2. Add caller-side validation of the keyspace name (non-empty, valid keyspace identifier) before issuing the call.
  3. If the name comes from user input, reject empty values at your API boundary with a clear message.

Example fix

// before
req := &vtctldatapb.CreateKeyspaceRequest{} // Name empty
// after
req := &vtctldatapb.CreateKeyspaceRequest{Name: "commerce"}
Defensive patterns

Strategy: validation

Validate before calling

if req.Name == "" {
	return errors.New("keyspace name is required")
}

Try / catch

resp, err := cluster.CreateKeyspace(ctx, req)
var inv *vtadminerrors.InvalidRequestError // via errors.Is
if err != nil {
	if errors.Is(err, vtadminerrors.ErrInvalidRequest) {
		return status.Errorf(codes.InvalidArgument, "check keyspace name: %v", err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling Cluster.CreateKeyspace with a request whose Name field is "" — e.g. &vtctldatapb.CreateKeyspaceRequest{} or a request built from an empty/unset user-supplied parameter.

Common situations: API consumers omitting the keyspace name in a POST body; CLI/tooling failing to populate the Name field; deserialization producing a zero-value request struct.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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