{"record":{"id":"eddd5c2736fb3833","repo":"JuliusBrussee/caveman","slug":"githubapp-request-failed-w","errorCode":null,"errorMessage":"githubapp: request failed: %w","messagePattern":"githubapp: request failed: %w","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":384,"sourceCode":"\t\tb, err := json.Marshal(body)\n\t\tif err != nil {\n\t\t\treturn 0, nil, fmt.Errorf(\"githubapp: marshal request: %w\", err)\n\t\t}\n\t\treader = bytes.NewReader(b)\n\t}\n\treq, err := http.NewRequestWithContext(ctx, method, target.String(), reader)\n\tif err != nil {\n\t\treturn 0, nil, fmt.Errorf(\"githubapp: build request: %w\", err)\n\t}\n\treq.Header.Set(\"Authorization\", authorization)\n\treq.Header.Set(\"Accept\", \"application/vnd.github+json\")\n\treq.Header.Set(\"X-GitHub-Api-Version\", \"2022-11-28\")\n\tif body != nil {\n\t\treq.Header.Set(\"Content-Type\", \"application/json\")\n\t}\n\tresp, err := a.httpClient.Do(req)\n\tif err != nil {\n\t\treturn 0, nil, fmt.Errorf(\"githubapp: request failed: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\traw, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20))\n\tif err != nil {\n\t\treturn resp.StatusCode, nil, fmt.Errorf(\"githubapp: read response: %w\", err)\n\t}\n\treturn resp.StatusCode, raw, nil\n}\n\n// parseRSAPrivateKey accepts a PKCS#1 (\"RSA PRIVATE KEY\") or PKCS#8\n// (\"PRIVATE KEY\") PEM — GitHub Apps download PKCS#1, but Cloud KMS / openssl\n// conversions emit PKCS#8, so we accept both.\nfunc parseRSAPrivateKey(pemBytes []byte) (*rsa.PrivateKey, error) {\n\tblock, _ := pem.Decode(pemBytes)\n\tif block == nil {\n\t\treturn nil, fmt.Errorf(\"githubapp: private key is not valid PEM\")\n\t}\n\tif key, err := x509.ParsePKCS1PrivateKey(block.Bytes); err == nil {","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L366-L402","documentation":"do() executed the request via the App's HTTP client and the transport itself failed — DNS resolution, TCP connect, TLS handshake, context cancellation, or a proxy error. This error wraps the underlying *url.Error; note it returns (0, nil, err), so no status code is available. Unlike HTTP 4xx/5xx, this is a transport-level failure.","triggerScenarios":"Calling any App method (GetInstallation, MintInstallationToken, RevokeToken, GetRepo, GetRepoInstallation, GetFileContent, DoToken) when the network is unreachable, DNS for api.github.com (or the GHE host) fails, TLS is rejected, an egress proxy is down, or the ctx deadline fires mid-request.","commonSituations":"Corporate proxy/firewall blocking api.github.com; running in an air-gapped environment pointing at an unreachable GHE host; context timeout too aggressive; VPN disconnected; DNS misconfiguration in containers (no resolv.conf entry for the host).","solutions":["Unwrap the error and check for context.DeadlineExceeded — if so, retry with a longer timeout or add retry with backoff.","Verify network egress: curl -v https://api.github.com from the same host/container to isolate DNS vs TLS vs proxy.","Check proxy environment variables (HTTPS_PROXY/NO_PROXY) — the default http.Transport honors them; ensure the GitHub host is reachable through the configured proxy.","Confirm the baseURL host resolves (nslookup) and, for GitHub Enterprise, that the CA is trusted by the client's TLS config."],"exampleFix":"// before\nctx := context.Background()\ninst, err := app.GetInstallation(ctx, tok) // hangs then dies behind proxy\n// after\nctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\ndefer cancel()\ninst, err := app.GetInstallation(ctx, tok)\nif err != nil {\n    var netErr net.Error\n    if errors.As(err, &netErr) && netErr.Timeout() {\n        // retry with backoff\n    }\n}","handlingStrategy":"retry","validationCode":"// reachability probe before batch operations\nreq, _ := http.NewRequestWithContext(ctx, \"GET\", baseURL+\"/zen\", nil)\nif _, err := http.DefaultClient.Do(req); err != nil {\n    return fmt.Errorf(\"GitHub API unreachable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"var netErr net.Error\nif errors.As(err, &netErr) && netErr.Timeout() {\n    // retry with backoff\n}\nif errors.Is(err, context.DeadlineExceeded) {\n    // extend deadline or abort batch\n}","preventionTips":["Set explicit context timeouts on every call.","Verify egress/proxy config (HTTPS_PROXY, NO_PROXY) in deployment.","Warm up DNS / add health checks for GitHub Enterprise hosts.","Use retry with exponential backoff for idempotent GETs."],"tags":["github","network","http-client","dns"],"backgroundTag":"http-request-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}