weaviate/weaviate · error
can't create the default handler, as no api is set
Error message
can't create the default handler, as no api is set
What it means
Server.Serve starts the REST server. If no handler was configured via SetHandler, it falls back to building a default handler from the configured api; if s.api is also nil there is nothing to serve, so it fails fast with this error. It is a wiring/initialization error, not a runtime request error.
Source
Thrown at adapters/handlers/rest/server.go:174
if v == scheme {
return true
}
}
return false
}
// Serve the api
func (s *Server) Serve() (err error) {
if !s.hasListeners {
if err = s.Listen(); err != nil {
return err
}
}
// set default handler, if none is set
if s.handler == nil {
if s.api == nil {
return errors.New("can't create the default handler, as no api is set")
}
s.SetHandler(s.api.Serve(nil))
}
wg := new(sync.WaitGroup)
once := new(sync.Once)
signalNotify(s.interrupt)
go handleInterrupt(once, s)
servers := []*http.Server{}
if s.hasScheme(schemeUnix) {
domainSocket := new(http.Server)
domainSocket.MaxHeaderBytes = int(s.MaxHeaderSize)
domainSocket.Handler = s.handler
if int64(s.CleanupTimeout) > 0 {
domainSocket.IdleTimeout = s.CleanupTimeoutView on GitHub (pinned to 75aa4b6d11)
Solutions
- Call SetApi with the built API (or construct via the standard configure function) before calling Serve.
- Alternatively provide a handler explicitly with SetHandler before Serve.
- Check initialization order: ensure configure_api/MakeAppState runs before server.Serve.
- Add an integration test that boots the server to catch missing wiring early.
Example fix
// before
srv := &server{} // no api, no handler
srv.Serve(ctx)
// after
srv := &server{}
srv.SetApi(api) // or srv.SetHandler(api.Serve(nil))
if err := srv.Serve(ctx); err != nil { log.Fatalf("server init: %v", err) } Defensive patterns
Strategy: validation
Validate before calling
if s.handler == nil && s.api == nil {
return errors.New("server misconfigured: neither handler nor api set; call SetApi or SetHandler before Serve")
} Type guard
func (s *Server) isWired() bool { return s.handler != nil || s.api != nil } Try / catch
if err := srv.Serve(ctx); err != nil {
if strings.Contains(err.Error(), "no api is set") {
log.Fatalf("wiring bug: build the API via configure_api/MakeAppState before Serve")
}
return err
} Prevention
- Always build the server through the standard configure_api/MakeAppState path.
- Set api/handler immediately after construction, before any Serve call.
- Add a smoke test that starts the server and issues a /v1/meta request.
- Fail fast in code reviews on server structs created with composite literals.
When it happens
Trigger: Constructing a server struct with neither SetHandler(...) nor the api field set, then calling Serve — e.g. custom embeddings of the server package or test harnesses that forget to call SetApi/SetHandler.
Common situations: Embedding weaviate's server into another binary and skipping the standard MakeAppState/configure_api wiring; unit tests instantiating server{} directly; refactor that renamed or reordered initialization calls so api is set after Serve.
Related errors
- required variable GPT4ALL_INFERENCE_API is not set
- NAMESPACES_ENABLED=true but cluster has %d non-namespaced co
- NAMESPACES_ENABLED=false but cluster has %d existing namespa
- NAMESPACES_ENABLED=false but cluster has %d namespace-qualif
- expect integer as raft port: got %s:: %w
AI-assisted analysis of weaviate/weaviate@75aa4b6d11 (2026-09-04).
Data as JSON: /api/errors/3c1345e092e89407.
Report an issue: GitHub.