{"record":{"id":"3c1345e092e89407","repo":"weaviate/weaviate","slug":"can-t-create-the-default-handler-as-no-api-is-set","errorCode":null,"errorMessage":"can't create the default handler, as no api is set","messagePattern":"can't create the default handler, as no api is set","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"adapters/handlers/rest/server.go","lineNumber":174,"sourceCode":"\t\tif v == scheme {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\n// Serve the api\nfunc (s *Server) Serve() (err error) {\n\tif !s.hasListeners {\n\t\tif err = s.Listen(); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\t// set default handler, if none is set\n\tif s.handler == nil {\n\t\tif s.api == nil {\n\t\t\treturn errors.New(\"can't create the default handler, as no api is set\")\n\t\t}\n\n\t\ts.SetHandler(s.api.Serve(nil))\n\t}\n\n\twg := new(sync.WaitGroup)\n\tonce := new(sync.Once)\n\tsignalNotify(s.interrupt)\n\tgo handleInterrupt(once, s)\n\n\tservers := []*http.Server{}\n\n\tif s.hasScheme(schemeUnix) {\n\t\tdomainSocket := new(http.Server)\n\t\tdomainSocket.MaxHeaderBytes = int(s.MaxHeaderSize)\n\t\tdomainSocket.Handler = s.handler\n\t\tif int64(s.CleanupTimeout) > 0 {\n\t\t\tdomainSocket.IdleTimeout = s.CleanupTimeout","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/adapters/handlers/rest/server.go#L156-L192","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nsrv := &server{} // no api, no handler\nsrv.Serve(ctx)\n\n// after\nsrv := &server{}\nsrv.SetApi(api) // or srv.SetHandler(api.Serve(nil))\nif err := srv.Serve(ctx); err != nil { log.Fatalf(\"server init: %v\", err) }","handlingStrategy":"validation","validationCode":"if s.handler == nil && s.api == nil {\n  return errors.New(\"server misconfigured: neither handler nor api set; call SetApi or SetHandler before Serve\")\n}","typeGuard":"func (s *Server) isWired() bool { return s.handler != nil || s.api != nil }","tryCatchPattern":"if err := srv.Serve(ctx); err != nil {\n  if strings.Contains(err.Error(), \"no api is set\") {\n    log.Fatalf(\"wiring bug: build the API via configure_api/MakeAppState before Serve\")\n  }\n  return err\n}","preventionTips":["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."],"tags":["server","startup","configuration"],"backgroundTag":"server-not-initialized","analyzedSha":"75aa4b6d11f8818305aafd4440b4e32794f7ca04","analyzedAt":"2026-09-04T14:58:20.392Z","contentChangedAt":"2026-09-04T14:58:20.392Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}