{"record":{"id":"63be767fb29b14bf","repo":"JuliusBrussee/caveman","slug":"githubapp-decode-repo-installation-w","errorCode":null,"errorMessage":"githubapp: decode repo installation: %w","messagePattern":"githubapp: decode repo installation: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":288,"sourceCode":"// GetRepoInstallation asks GitHub which installation of this App owns access to\n// a repository. This avoids treating public repository visibility as proof that\n// a caller-supplied installation id is authorized for that repository.\nfunc (a *App) GetRepoInstallation(ctx context.Context, owner, name string) (Installation, error) {\n\tvar out Installation\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\"/repos/\"+url.PathEscape(owner)+\"/\"+url.PathEscape(name)+\"/installation\", 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 repo installation %s/%s: HTTP %d: %s\", owner, name, status, snippet(raw))\n\t}\n\tif err := json.Unmarshal(raw, &out); err != nil {\n\t\treturn out, fmt.Errorf(\"githubapp: decode repo installation: %w\", err)\n\t}\n\tif out.ID <= 0 {\n\t\treturn Installation{}, fmt.Errorf(\"githubapp: repo installation response carried no id\")\n\t}\n\treturn out, nil\n}\n\n// GetFileContent reads one repository file with an installation token. The\n// content endpoint returns base64; callers receive decoded bytes with a strict\n// 64 KiB post-decode ceiling because connection proofs are tiny text files.\nfunc (a *App) GetFileContent(ctx context.Context, token, owner, name, path, ref string) ([]byte, error) {\n\tsegments := strings.Split(strings.Trim(path, \"/\"), \"/\")\n\tif len(segments) == 0 || segments[0] == \"\" {\n\t\treturn nil, fmt.Errorf(\"githubapp: content path is required\")\n\t}\n\tfor i := range segments {\n\t\tsegments[i] = url.PathEscape(segments[i])\n\t}","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L270-L306","documentation":"Wrapped decode error from GetRepoInstallation: the GitHub API call for /repos/{owner}/{name}/installation succeeded (HTTP 200) but the JSON body could not be unmarshalled into the Installation struct. The decode error is included via %w; the API response shape was not what the client expects.","triggerScenarios":"A 200 response whose body is not valid Installation JSON — proxy-injected HTML with 200, GitHub schema change to the installation object, or truncated body.","commonSituations":"Middleboxes returning success pages; API changes on the /installation endpoint; misrouted request hitting a login page (200 HTML).","solutions":["Unwrap with errors.As to distinguish SyntaxError vs TypeMismatchError and log the raw body at debug level","Compare the actual response fields with the Installation struct's JSON tags","Bypass proxies/VPNs and hit api.github.com directly to reproduce","Update struct definitions if GitHub changed the installation payload shape"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"var syn *json.SyntaxError\nif errors.As(err, &syn) {\n    log.Printf(\"installation payload not JSON — inspect proxy/response body\")\n}","preventionTips":["Bypass middleboxes that inject HTML on 200 responses","Log raw bodies on decode failure","Keep the Installation struct aligned with the current GitHub schema"],"tags":["github","json","decoding"],"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"}