{"record":{"id":"e3e6f3416ab276b8","repo":"router-for-me/CLIProxyAPI","slug":"failed-to-start-https-server-tls-cert-or-tls-key","errorCode":null,"errorMessage":"failed to start HTTPS server: tls.cert or tls.key is empty","messagePattern":"failed to start HTTPS server: tls\\.cert or tls\\.key is empty","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/api/server.go","lineNumber":281,"sourceCode":"\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}\n\t\tcertPair, errLoad := tls.LoadX509KeyPair(certPath, keyPath)\n\t\tif errLoad != nil {\n\t\t\tif errClose := listener.Close(); errClose != nil {\n\t\t\t\tlog.Errorf(\"failed to close listener after TLS key pair load failure: %v\", errClose)\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"failed to start HTTPS server: %v\", errLoad)\n\t\t}\n\n\t\ttlsConfig := &tls.Config{\n\t\t\tCertificates: []tls.Certificate{certPair},\n\t\t\tNextProtos:   []string{\"h2\", \"http/1.1\"},\n\t\t}\n\t\ts.server.TLSConfig = tlsConfig\n\t\tif errHTTP2 := http2.ConfigureServer(s.server, &http2.Server{}); errHTTP2 != nil {\n\t\t\tlog.Warnf(\"failed to configure HTTP/2: %v\", errHTTP2)\n\t\t}\n\t\tlistener = tls.NewListener(listener, tlsConfig)","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/api/server.go#L263-L299","documentation":"Error \"failed to start HTTPS server: tls.cert or tls.key is empty\" thrown in router-for-me/CLIProxyAPI.","triggerScenarios":"Thrown at internal/api/server.go:281 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set both tls.cert and tls.key in the configuration before enabling HTTPS.","Provide valid paths to the TLS certificate and private key files in config.yaml."],"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-15T17:31:12.345Z"}