{"record":{"id":"d87556dc3288047c","repo":"router-for-me/CLIProxyAPI","slug":"failed-to-start-http-server-server-not-initialize","errorCode":null,"errorMessage":"failed to start HTTP server: server not initialized","messagePattern":"failed to start HTTP server: server not initialized","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/api/server.go","lineNumber":264,"sourceCode":"\t}\n\n\t// Create HTTP server\n\ts.server = &http.Server{\n\t\tAddr:    fmt.Sprintf(\"%s:%d\", cfg.Host, cfg.Port),\n\t\tHandler: engine,\n\t}\n\n\treturn s\n}\n\n// Start begins listening for and serving HTTP or HTTPS requests.\n// It's a blocking call and will only return on an unrecoverable error.\n//\n// Returns:\n//   - error: An error if the server fails to start\nfunc (s *Server) Start() error {\n\tif s == nil || s.server == nil {\n\t\treturn fmt.Errorf(\"failed to start HTTP server: server not initialized\")\n\t}\n\n\taddr := s.server.Addr\n\tlistener, errListen := net.Listen(\"tcp\", addr)\n\tif errListen != nil {\n\t\treturn fmt.Errorf(\"failed to start HTTP server: %v\", errListen)\n\t}\n\n\tuseTLS := s.cfg != nil && s.cfg.TLS.Enable\n\tif useTLS {\n\t\tcertPath := strings.TrimSpace(s.cfg.TLS.Cert)\n\t\tkeyPath := strings.TrimSpace(s.cfg.TLS.Key)\n\t\tif certPath == \"\" || keyPath == \"\" {\n\t\t\tif errClose := listener.Close(); errClose != nil {\n\t\t\t\tlog.Errorf(\"failed to close listener after TLS validation failure: %v\", errClose)\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"failed to start HTTPS server: tls.cert or tls.key is empty\")\n\t\t}","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/api/server.go#L246-L282","documentation":"Error \"failed to start HTTP server: server not initialized\" thrown in router-for-me/CLIProxyAPI.","triggerScenarios":"Thrown at internal/api/server.go:264 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the server instance is fully constructed before calling Start.","Check initialization order in cmd/server so the HTTP server is initialized prior to startup."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}