{"record":{"id":"52315c25b2c4ee52","repo":"Jguer/yay","slug":"invalid-status-code-d","errorCode":null,"errorMessage":"invalid status code: %d","messagePattern":"invalid status code: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/download/aur.go","lineNumber":138,"sourceCode":"// GetPackageScanner fetches the AUR packages.gz file and returns a scanner for reading its contents.\n// The caller must call Close() on the returned ScannerCloser when done to properly release resources.\nfunc GetPackageScanner(ctx context.Context, client HTTPRequestDoer, aurURL string, logger *text.Logger) (*ScannerCloser, error) {\n\tu, err := url.Parse(aurURL)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tu.Path = path.Join(u.Path, \"packages.gz\")\n\tpackagesURL := u.String()\n\n\tresp, err := client.Get(packagesURL)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tresp.Body.Close()\n\t\treturn nil, fmt.Errorf(\"invalid status code: %d\", resp.StatusCode)\n\t}\n\n\t// Read the entire body to allow trying gzip decompression\n\tbody, err := io.ReadAll(resp.Body)\n\tresp.Body.Close()\n\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Try to decompress as gzip; if that fails, use raw body\n\tvar reader io.Reader\n\tvar closer io.Closer\n\n\tgzReader, gzErr := gzip.NewReader(bytes.NewReader(body))\n\tif gzErr == nil {\n\t\treader = gzReader\n\t\tcloser = gzReader","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/Jguer/yay/blob/328f4b4939fb35f38c2f7c7ce3b8638a839bafa5/pkg/download/aur.go#L120-L156","documentation":"GetPackageScanner fetches a package list (AUR packages.gz / packages-metadata) over HTTP and requires HTTP 200. Any other status (404, 403, 5xx) closes the body and returns 'invalid status code: <code>'. Callers like syncList and createAURList then fail to build the AUR package list.","triggerScenarios":"The HTTP GET of the AUR metadata endpoint returns a non-200 status: AUR server outage/503, wrong aurUrl in config, rate limiting (429), captive proxy returning 403, or DNS/routing to a stale mirror returning 404.","commonSituations":"AUR maintenance windows or heavy load (5xx); custom aururl pointing at an old domain; corporate proxy blocking the request; typos in aururl config.","solutions":["Retry later or check https://status.archlinux.org — 5xx/429 usually means AUR is down or rate-limiting","Verify the aururl config (yay -Pg) points to https://aur.archlinux.org and correct it if overridden","Test connectivity manually: curl -I https://aur.archlinux.org/packages.gz to see the actual status","If behind a proxy, set/clear HTTP(S)_PROXY env vars and ensure they allow the AUR domain"],"exampleFix":"// before\nresp, _ := http.Get(aurURL + \"/packages.gz\") // blindly fails: invalid status code: 503\n// after\nresp, _ := http.Get(aurURL + \"/packages.gz\")\nif resp != nil && resp.StatusCode == http.StatusTooManyRequests {\n    time.Sleep(retryAfterDelay(resp)) // honor backoff, then retry once\n    resp, _ = http.Get(aurURL + \"/packages.gz\")\n}\n// and check configured URL: curl -I $aurUrl/packages.gz before blaming the client","handlingStrategy":"retry","validationCode":"u := cfg.AurURL + \"/packages.gz\"\nif pu, err := url.Parse(u); err != nil || pu.Scheme != \"https\" || pu.Host == \"\" {\n    return fmt.Errorf(\"invalid aurUrl %q\", u)\n}\n// preflight: resp, err := http.Head(u); ok := err == nil && resp.StatusCode == 200","typeGuard":null,"tryCatchPattern":"var body []byte\nfor attempt := 0; attempt < 3; attempt++ {\n    body, err = fetchPackagesGz(ctx)\n    if err == nil { break }\n    var sce interface{ StatusCode() int }\n    if errors.As(err, &anyResp{}) || strings.Contains(err.Error(), \"invalid status code\") {\n        time.Sleep(time.Duration(1<<attempt) * time.Second) // backoff for 429/5xx\n        continue\n    }\n    return err\n}","preventionTips":["Check https://status.archlinux.org before blaming your code on AUR 5xx","Don't override aururl unless you mirror the AUR; verify with curl -I","Honor 429/Retry-After; poll at reasonable intervals (the AUR rate-limits)","Set correct proxy env vars in CI/container environments"],"tags":["network","http","aur"],"backgroundTag":"http-non-200-response","analyzedSha":"328f4b4939fb35f38c2f7c7ce3b8638a839bafa5","analyzedAt":"2026-09-07T16:45:12.608Z","contentChangedAt":"2026-09-07T16:45:12.608Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}