{"record":{"id":"a47d15f15e9a66d1","repo":"hashicorp/terraform","slug":"invalid-response-content-from-mirror-server-s","errorCode":null,"errorMessage":"invalid response content from mirror server: %s","messagePattern":"invalid response content from mirror server: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/getproviders/http_mirror_source.go","lineNumber":146,"sourceCode":"\tcase http.StatusOK:\n\t\t// Great!\n\tcase http.StatusNotFound:\n\t\treturn nil, nil, ErrProviderNotFound{\n\t\t\tProvider: provider,\n\t\t}\n\tcase http.StatusUnauthorized, http.StatusForbidden:\n\t\treturn nil, nil, s.errUnauthorized(finalURL)\n\tdefault:\n\t\treturn nil, nil, s.errQueryFailed(provider, fmt.Errorf(\"server returned unsuccessful status %d\", statusCode))\n\t}\n\n\t// If we got here then the response had status OK and so our body\n\t// will be non-nil and should contain some JSON for us to parse.\n\tvar bodyContent ListVersionsResponseBody\n\n\tdec := json.NewDecoder(body)\n\tif err := dec.Decode(&bodyContent); err != nil {\n\t\treturn nil, nil, s.errQueryFailed(provider, fmt.Errorf(\"invalid response content from mirror server: %s\", err))\n\t}\n\n\tif len(bodyContent.Versions) == 0 {\n\t\treturn nil, nil, nil\n\t}\n\tret := make(VersionList, 0, len(bodyContent.Versions))\n\tfor versionStr := range bodyContent.Versions {\n\t\tversion, err := ParseVersion(versionStr)\n\t\tif err != nil {\n\t\t\tlog.Printf(\"[WARN] Ignoring invalid %s version string %q in provider mirror response\", provider, versionStr)\n\t\t\tcontinue\n\t\t}\n\t\tret = append(ret, version)\n\t}\n\n\tret.Sort()\n\treturn ret, nil, nil\n}","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/getproviders/http_mirror_source.go#L128-L164","documentation":"After a 200 response on the mirror's version index, the body is decoded as JSON into `ListVersionsResponseBody`. If `json.Decode` fails (malformed JSON, schema mismatch, truncated body), the decode error is wrapped and surfaced via `ErrQueryFailed`. It means the mirror server returned non-JSON or structurally invalid JSON.","triggerScenarios":"`json.NewDecoder(body).Decode(&bodyContent)` fails for the version listing; error at http_mirror_source.go:146.","commonSituations":"Mirror serves HTML error page (but with 200) instead of JSON; proxy injecting content; truncated large response; hand-rolled mirror with wrong JSON shape; encoding/charset issue.","solutions":["`curl` the index URL and pipe through `jq .` to confirm valid JSON.","Fix the mirror to serve a `ListVersionsResponseBody`-shaped object (`{\"versions\": {...}}`).","Ensure no proxy rewrites the body; check `Content-Encoding` and decompression.","If the mirror is unfixable, remove the `network_mirror` block."],"exampleFix":"// before: mirror returns HTML\nGET /hashicorp/aws/index.json -> 200, <html>...</html>\n// after: mirror returns JSON\nGET /hashicorp/aws/index.json -> 200\n{\"versions\":{\"4.0\":{},\"4.1\":{}}}","handlingStrategy":"validation","validationCode":"// Validate served JSON shape before consumers hit it\nvar probe ListVersionsResponseBody\nif err := json.Unmarshal(raw, &probe); err != nil {\n    return fmt.Errorf(\"mirror index JSON invalid: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"// Treat decode errors as retryable / fall back\nversions, err := src.AvailableVersions(ctx, provider)\nif err != nil && strings.Contains(err.Error(), \"invalid response content\") {\n    versions, err = defaultRegistry.AvailableVersions(ctx, provider)\n}","preventionTips":["Serve JSON with `Content-Type: application/json` from the mirror.","Validate mirror JSON with a schema before publishing.","Use a CDN that does not inject HTML on errors.","Smoke-test mirror responses with `jq`."],"tags":["network","mirror","json","registry"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}