{"record":{"id":"9cfd24d274fc9eda","repo":"hashicorp/packer","slug":"failed-to-download-s-w","errorCode":null,"errorMessage":"failed to download %s: %w","messagePattern":"failed to download (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/hcp-sbom/packer_release_fetch.go","lineNumber":153,"sourceCode":"\t}\n\tif closeErr != nil {\n\t\t_ = os.Remove(tmpPath)\n\t\treturn \"\", fmt.Errorf(\"failed to close temp file: %w\", closeErr)\n\t}\n\n\treturn tmpPath, nil\n}\n\n// downloadChecksumFile fetches the SHA256SUMS text file at url.\nfunc downloadChecksumFile(ctx context.Context, client *http.Client, url string) (string, error) {\n\treq, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to build request for %s: %w\", url, err)\n\t}\n\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to download %s: %w\", url, err)\n\t}\n\tdefer func() { _ = resp.Body.Close() }()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn \"\", fmt.Errorf(\"download failed: HTTP %d for %s\", resp.StatusCode, url)\n\t}\n\n\tbody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed reading response body for %s: %w\", url, err)\n\t}\n\tif len(strings.TrimSpace(string(body))) == 0 {\n\t\treturn \"\", fmt.Errorf(\"empty response body for %s\", url)\n\t}\n\n\treturn string(body), nil\n}\n","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/hcp-sbom/packer_release_fetch.go#L135-L171","documentation":"downloadChecksumFile issued the GET for the SHA256SUMS file but client.Do returned an error, meaning no usable HTTP response was received: DNS failure, TCP connect failure, TLS handshake error, request canceled via context, or a client-side policy/redirect error. The error is wrapped with the URL so the failing endpoint is identified directly.","triggerScenarios":"client.Do(req) returns a non-nil *url.Error while fetching <base>/packer/<v>/packer_<v>_SHA256SUMS — network unreachable, DNS resolution failure for releases.hashicorp.com, TLS interception/certificate problems, or ctx canceled/timed out mid-request.","commonSituations":"Build machine has no outbound internet access or a proxy is required but not configured (HTTP_PROXY/HTTPS_PROXY); corporate firewall blocks releases.hashicorp.com; DNS misconfiguration in CI containers; transient network blip during a Packer build; context deadline exceeded on slow links.","solutions":["Verify outbound connectivity to the URL shown in the error (curl -v <url>) from the machine running Packer","Configure proxy environment variables (HTTPS_PROXY/HTTP_PROXY/NO_PROXY) if the network requires a proxy","Check DNS resolution (nslookup releases.hashicorp.com) and firewall/egress rules in CI or cloud security groups","Rely on the built-in retry — downloadPackerRelease retries the whole flow 3 times with 5s delay; if failures persist, investigate the network path","Ensure the context passed to the build is not being canceled early by an upstream timeout"],"exampleFix":"// before: no proxy configured in CI, client.Do fails\n// after: export proxy vars before running packer\n// $ export HTTPS_PROXY=http://proxy.corp.example:3128\n// $ export NO_PROXY=localhost,127.0.0.1\n// $ packer build template.pkr.hcl","handlingStrategy":"retry","validationCode":"// preflight reachability check before the real flow\nreq, err := http.NewRequestWithContext(ctx, http.MethodHead, base+\"/packer/index.json\", nil)\nif err != nil {\n    return err\n}\nresp, err := client.Do(req)\nif err != nil {\n    return fmt.Errorf(\"releases host unreachable (check network/proxy/DNS): %w\", err)\n}\n_ = resp.Body.Close()","typeGuard":"// detect transport-level failures suitable for retry vs. permanent errors\nfunc isRetryableURLError(err error) bool {\n    var ue *url.Error\n    if !errors.As(err, &ue) {\n        return false\n    }\n    if errors.Is(ue.Err, context.Canceled) {\n        return false\n    }\n    var ne net.Error\n    return errors.As(ue.Err, &ne) || errors.Is(ue.Err, io.EOF) || ue.Timeout()\n}","tryCatchPattern":"_, err := downloadChecksumFile(ctx, client, shaSumsURL)\nif err != nil {\n    var ue *url.Error\n    if errors.As(err, &ue) {\n        return fmt.Errorf(\"network error reaching %s (op=%s): %w\", ue.URL, ue.Op, err)\n    }\n    return err\n}","preventionTips":["Configure HTTPS_PROXY/HTTP_PROXY/NO_PROXY when building behind a corporate proxy","Allowlist releases.hashicorp.com in firewalls and cloud egress rules","Verify DNS resolution inside CI containers","Set generous context deadlines; ensure no upstream cancels the build context mid-download","Use the SDK retry.Config (as downloadPackerRelease does) around any direct calls"],"tags":["go","http","network","dns","proxy"],"backgroundTag":"http-request-failed","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}