vitessio/vitess · error · errors.ErrInvalidRequest
%w: request cannot be nil
Error message
%w: request cannot be nil
What it means
CreateKeyspace validates its request before doing any work and returns errors.ErrInvalidRequest wrapped with this message when the caller passes a nil *vtctldatapb.CreateKeyspaceRequest. It is a defensive guard so the RPC layer fails fast with a typed invalid-request error instead of panicking on a nil dereference.
Source
Thrown at go/vt/vtadmin/cluster/cluster.go:429
defer span.Finish()
AnnotateSpan(c, span)
span.Annotate("keyspace", req.Keyspace)
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
}
View on GitHub (pinned to 01a25a7d17)
Solutions
- Pass a non-nil *vtctldatapb.CreateKeyspaceRequest, e.g. &vtctldatapb.CreateKeyspaceRequest{Name: "commerce"}.
- If calling through an HTTP/JSON layer, ensure the request body deserializes into a request object rather than nil.
- Guard your own call site with `if req == nil` before invoking CreateKeyspace.
Example fix
// before
resp, err := cluster.CreateKeyspace(ctx, nil)
// after
req := &vtctldatapb.CreateKeyspaceRequest{Name: "commerce"}
resp, err := cluster.CreateKeyspace(ctx, req) Defensive patterns
Strategy: try-catch
Validate before calling
if req == nil {
return errors.New("CreateKeyspace requires a non-nil request")
} Try / catch
resp, err := cluster.CreateKeyspace(ctx, req)
if err != nil {
if errors.Is(err, vtadminerrors.ErrInvalidRequest) && strings.Contains(err.Error(), "request cannot be nil") {
// fix the call site: construct a request object
return fmt.Errorf("bug in caller: nil CreateKeyspaceRequest: %w", err)
}
return err
} Prevention
- Always construct request structs explicitly; never pass nil protobuf requests to vtadmin Cluster methods.
- Centralize vtadmin calls in helpers that default-construct requests.
- Cover API helpers with tests that assert non-nil requests are built.
When it happens
Trigger: Calling Cluster.CreateKeyspace(ctx, nil) directly from Go code, or an RPC/HTTP handler that forwards a nil request into the vtadmin API without first checking it.
Common situations: Hand-written clients calling the vtadmin API Go package directly; gRPC handlers receiving a nil request message; tests invoking CreateKeyspace without constructing a request.
Related errors
- %w: keyspace name is required
- %w: keyspace name is required
- %w: shard name is required
- invalid joined path
- BaseKeyspace is required for SNAPSHOT keyspaces
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/3c468481dda8423d.
Report an issue: GitHub.