{"record":{"id":"6e4169981cadaecb","repo":"JuliusBrussee/caveman","slug":"githubapp-decode-installation-w","errorCode":null,"errorMessage":"githubapp: decode installation: %w","messagePattern":"githubapp: decode installation: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":175,"sourceCode":"func (a *App) GetInstallation(ctx context.Context, installationID int64) (Installation, error) {\n\tvar out Installation\n\tif installationID <= 0 {\n\t\treturn out, fmt.Errorf(\"githubapp: installation id must be positive\")\n\t}\n\tjwt, err := a.AppJWT()\n\tif err != nil {\n\t\treturn out, err\n\t}\n\tstatus, raw, err := a.do(ctx, \"Bearer \"+jwt, http.MethodGet,\n\t\t\"/app/installations/\"+strconv.FormatInt(installationID, 10), nil)\n\tif err != nil {\n\t\treturn out, err\n\t}\n\tif status != http.StatusOK {\n\t\treturn out, fmt.Errorf(\"githubapp: get installation: HTTP %d: %s\", status, snippet(raw))\n\t}\n\tif err := json.Unmarshal(raw, &out); err != nil {\n\t\treturn out, fmt.Errorf(\"githubapp: decode installation: %w\", err)\n\t}\n\tif out.ID != installationID || out.Account.ID <= 0 || strings.TrimSpace(out.Account.Login) == \"\" {\n\t\treturn Installation{}, fmt.Errorf(\"githubapp: installation response identity mismatch\")\n\t}\n\treturn out, nil\n}\n\n// MintInstallationToken POSTs /app/installations/{id}/access_tokens narrowed to\n// `repos` and `perms`, returning a ~1h token. Defaults (perms nil) are\n// contents:write + pull_requests:write — enough to push a branch and open a draft\n// PR, never to merge.\nfunc (a *App) MintInstallationToken(ctx context.Context, installationID int64, repos []string, perms map[string]string) (InstallationToken, error) {\n\tif installationID <= 0 {\n\t\treturn InstallationToken{}, fmt.Errorf(\"githubapp: installation id must be positive\")\n\t}\n\tif len(repos) != 1 || strings.TrimSpace(repos[0]) == \"\" {\n\t\treturn InstallationToken{}, fmt.Errorf(\"githubapp: exactly one repository is required\")\n\t}","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L157-L193","documentation":"The endpoint returned HTTP 200 but the body could not be parsed as the expected Installation JSON. The library wraps the json.Unmarshal error with this prefix. This indicates GitHub's response did not match the expected schema or was truncated/corrupted.","triggerScenarios":"App.GetInstallation receives a 200 whose body is not valid JSON or does not match the Installation struct (e.g. an HTML error page, an empty body, or a proxy/interception layer returning unexpected content).","commonSituations":"Corporate proxies or API mocks returning HTML; GitHub returning an unusual payload during API changes; a test server returning the wrong fixture shape.","solutions":["Log the raw body (it is in the wrapped error chain) to see what was actually returned","If behind a proxy, bypass it or fix its response content type","Update the library if GitHub changed the response schema","In tests, fix the fixture so it matches the real /app/installations/{id} payload"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// No pre-call validation possible; ensure no proxy rewrites api.github.com responses","typeGuard":"func isDecodeErr(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"decode installation:\")\n}","tryCatchPattern":"inst, err := app.GetInstallation(ctx, id)\nif err != nil {\n\tif isDecodeErr(err) {\n\t\tlog.Printf(\"unexpected installation payload: %v\", err)\n\t\t// inspect raw body / bypass proxy; retry once\n\t}\n\treturn err\n}","preventionTips":["Do not route api.github.com through response-rewriting proxies","Keep the library updated for GitHub API schema changes","Use realistic fixtures in mock servers"],"tags":["github-app","json","api"],"backgroundTag":"json-unmarshal-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"}