{"record":{"id":"7e2ade9f5d58cb0d","repo":"charmbracelet/crush","slug":"failed-to-fetch-url-w-7e2ade","errorCode":null,"errorMessage":"failed to fetch URL: %w","messagePattern":"failed to fetch URL: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/sourcegraph.go","lineNumber":125,"sourceCode":"\t\t\t}\n\t\t\tgraphqlQuery := string(graphqlQueryBytes)\n\n\t\t\treq, err := http.NewRequestWithContext(\n\t\t\t\trequestCtx,\n\t\t\t\t\"POST\",\n\t\t\t\t\"https://sourcegraph.com/.api/graphql\",\n\t\t\t\tbytes.NewBuffer([]byte(graphqlQuery)),\n\t\t\t)\n\t\t\tif err != nil {\n\t\t\t\treturn fantasy.ToolResponse{}, fmt.Errorf(\"failed to create request: %w\", err)\n\t\t\t}\n\n\t\t\treq.Header.Set(\"Content-Type\", \"application/json\")\n\t\t\treq.Header.Set(\"User-Agent\", \"crush/1.0\")\n\n\t\t\tresp, err := client.Do(req)\n\t\t\tif err != nil {\n\t\t\t\treturn fantasy.ToolResponse{}, fmt.Errorf(\"failed to fetch URL: %w\", err)\n\t\t\t}\n\t\t\tdefer resp.Body.Close()\n\n\t\t\tif resp.StatusCode != http.StatusOK {\n\t\t\t\tbody, _ := io.ReadAll(resp.Body)\n\t\t\t\tif len(body) > 0 {\n\t\t\t\t\treturn fantasy.NewTextErrorResponse(fmt.Sprintf(\"Request failed with status code: %d, response: %s\", resp.StatusCode, string(body))), nil\n\t\t\t\t}\n\n\t\t\t\treturn fantasy.NewTextErrorResponse(fmt.Sprintf(\"Request failed with status code: %d\", resp.StatusCode)), nil\n\t\t\t}\n\t\t\tbody, err := io.ReadAll(resp.Body)\n\t\t\tif err != nil {\n\t\t\t\treturn fantasy.ToolResponse{}, fmt.Errorf(\"failed to read response body: %w\", err)\n\t\t\t}\n\n\t\t\tvar result map[string]any\n\t\t\tif err = json.Unmarshal(body, &result); err != nil {","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/agent/tools/sourcegraph.go#L107-L143","documentation":"Wraps a client.Do transport error when POSTing the GraphQL query to sourcegraph.com (internal/agent/tools/sourcegraph.go:123-126). No HTTP response was received at all: DNS failure, connection refused/reset, TLS errors, or the request context (tool Timeout param, max 120s, or client's 30s default) expired. Distinct from the non-200 branch, which produces a text error response instead.","triggerScenarios":"client.Do(req) returns an error: no internet/DNS resolution failure for sourcegraph.com, connection refused or reset, TLS handshake failure, context deadline exceeded from params.Timeout or the 30s default http.Client.Timeout, or a proxy blocking the request.","commonSituations":"Offline or air-gapped environments running the agent; corporate firewalls/proxies blocking sourcegraph.com; Sourcegraph outages; a large search with a small Timeout value exceeding the client's 30-second limit.","solutions":["Check basic connectivity to sourcegraph.com (curl https://sourcegraph.com/.api/graphql) and DNS.","Verify no proxy env vars (HTTP_PROXY/HTTPS_PROXY) or firewall rules block the host; configure a working proxy if required.","Retry with a larger Timeout param or after transient network failures; errors.Is(err, context.DeadlineExceeded) indicates a timeout.","Wait for Sourcegraph service recovery if status.sourcegraph.com reports an outage."],"exampleFix":"// before\ntool := NewSourcegraphTool(nil) // 30s default client\n\n// after\nclient := &http.Client{Timeout: 90 * time.Second}\ntool := NewSourcegraphTool(client)","handlingStrategy":"retry","validationCode":"resp, err := http.Head(\"https://sourcegraph.com\")\nif err != nil {\n    return fmt.Errorf(\"sourcegraph.com unreachable: %w\", err)\n}\nresp.Body.Close()","typeGuard":"var netErr net.Error\nif errors.As(err, &netErr) && netErr.Timeout() { /* timeout, not unreachable host */ }\nif errors.Is(err, context.DeadlineExceeded) { /* tool Timeout param too small */ }","tryCatchPattern":"out, err := toolCall(ctx, params)\nif err != nil {\n    var netErr net.Error\n    if errors.As(err, &netErr) && netErr.Timeout() {\n        // retry with larger Timeout param\n    } else if isNetworkUnreachable(err) {\n        // report connectivity problem to user\n    }\n    return err\n}","preventionTips":["Ensure outbound HTTPS to sourcegraph.com is allowed by firewall/proxy policy.","Set a Timeout param comfortably under the client's overall timeout.","Check DNS and proxy env vars (HTTP_PROXY/HTTPS_PROXY/NO_PROXY) in the execution environment.","Retry transient transport errors with backoff before surfacing to the model."],"tags":["network","http","dns","timeout"],"backgroundTag":"http-request-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}