{"record":{"id":"1d271c24aa8f1187","repo":"wavetermdev/waveterm","slug":"request-failed-w","errorCode":null,"errorMessage":"request failed: %w","messagePattern":"request failed: %w","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/aiusechat/openaichat/openaichat-backend.go","lineNumber":70,"sourceCode":"\t\tchatMsg, ok := genMsg.(*StoredChatMessage)\n\t\tif !ok {\n\t\t\treturn nil, nil, nil, fmt.Errorf(\"expected StoredChatMessage, got %T\", genMsg)\n\t\t}\n\t\tmessages = append(messages, *chatMsg.Message.clean())\n\t}\n\n\treq, err := buildChatHTTPRequest(ctx, messages, chatOpts)\n\tif err != nil {\n\t\treturn nil, nil, nil, err\n\t}\n\n\tclient, err := aiutil.MakeHTTPClient(chatOpts.Config.ProxyURL)\n\tif err != nil {\n\t\treturn nil, nil, nil, err\n\t}\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, nil, nil, fmt.Errorf(\"request failed: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tbodyBytes, _ := io.ReadAll(resp.Body)\n\t\treturn nil, nil, nil, fmt.Errorf(\"API returned status %d: %s\", resp.StatusCode, string(bodyBytes))\n\t}\n\n\t// Setup SSE if this is a new request (not a continuation)\n\tif cont == nil {\n\t\tif err := sseHandler.SetupSSE(); err != nil {\n\t\t\treturn nil, nil, nil, fmt.Errorf(\"failed to setup SSE: %w\", err)\n\t\t}\n\t}\n\n\t// Stream processing\n\tstopReason, assistantMsg, err := processChatStream(ctx, resp.Body, sseHandler, chatOpts, cont)\n\tif err != nil {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/aiusechat/openaichat/openaichat-backend.go#L52-L88","documentation":"After building the chat request, the HTTP client.Do call failed (DNS failure, connection refused, TLS error, timeout, proxy failure); RunChatStep wraps the transport error with 'request failed:' since no HTTP response was obtained at all.","triggerScenarios":"client.Do returns an error: network unreachable, proxy misconfigured (chatOpts.Config.ProxyURL), request context cancelled/timed out (including Config.TimeoutMs), or TLS handshake failure against the chat API endpoint.","commonSituations":"No internet or firewall blocking the endpoint; bad ProxyURL in Config; TimeoutMs too small for slow LLM responses; wrong API base URL; server outage.","solutions":["Inspect the wrapped error (%w chain) for the root cause (timeout vs DNS vs refused)","Verify network connectivity and the configured API endpoint URL","Check/clear Config.ProxyURL if a proxy is not intended or is misconfigured","Increase Config.TimeoutMs or the context deadline for long completions","Retry with backoff on transient transport failures"],"exampleFix":"// before\nresp, err := client.Do(req)\nif err != nil { return fmt.Errorf(\"request failed: %w\", err) }\n// after\nresp, err := client.Do(req)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) {\n        return fmt.Errorf(\"request timed out (increase TimeoutMs): %w\", err)\n    }\n    return retryable(fmt.Errorf(\"request failed: %w\", err))\n}","handlingStrategy":"retry","validationCode":"if chatOpts.Config.ProxyURL != \"\" {\n    if u, err := url.Parse(chatOpts.Config.ProxyURL); err != nil || u.Host == \"\" {\n        return fmt.Errorf(\"bad proxy URL: %v\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"resp, err := client.Do(req)\nif err != nil {\n    var nerr net.Error\n    if errors.As(err, &nerr) && nerr.Timeout() { /* retry with backoff */ }\n    if errors.Is(err, context.DeadlineExceeded) { /* raise TimeoutMs */ }\n    return fmt.Errorf(\"request failed: %w\", err)\n}","preventionTips":["Set realistic TimeoutMs for LLM latency","Verify ProxyURL and API endpoint configuration","Monitor connectivity and retry transient transport errors with backoff","Use errors.Is/As on the wrapped cause to classify failures"],"tags":["network","http","openai"],"backgroundTag":"http-request-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}