{"record":{"id":"6b7bd21b3b338ed8","repo":"JuliusBrussee/caveman","slug":"githubapp-decode-repository-proof-w","errorCode":null,"errorMessage":"githubapp: decode repository proof: %w","messagePattern":"githubapp: decode repository proof: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":325,"sourceCode":"\tendpoint := \"/repos/\" + url.PathEscape(owner) + \"/\" + url.PathEscape(name) + \"/contents/\" + strings.Join(segments, \"/\")\n\tif strings.TrimSpace(ref) != \"\" {\n\t\tendpoint += \"?\" + url.Values{\"ref\": {ref}}.Encode()\n\t}\n\tstatus, raw, err := a.do(ctx, \"Bearer \"+token, http.MethodGet, endpoint, nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif status != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"githubapp: get repository proof: HTTP %d: %s\", status, snippet(raw))\n\t}\n\tvar payload struct {\n\t\tType     string `json:\"type\"`\n\t\tEncoding string `json:\"encoding\"`\n\t\tContent  string `json:\"content\"`\n\t\tSize     int64  `json:\"size\"`\n\t}\n\tif err := json.Unmarshal(raw, &payload); err != nil {\n\t\treturn nil, fmt.Errorf(\"githubapp: decode repository proof: %w\", err)\n\t}\n\tif payload.Type != \"file\" || payload.Encoding != \"base64\" || payload.Size < 0 || payload.Size > 64<<10 {\n\t\treturn nil, fmt.Errorf(\"githubapp: repository proof has invalid type, encoding, or size\")\n\t}\n\tdecoded, err := base64.StdEncoding.DecodeString(strings.ReplaceAll(payload.Content, \"\\n\", \"\"))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"githubapp: decode repository proof content: %w\", err)\n\t}\n\tif len(decoded) > 64<<10 || int64(len(decoded)) != payload.Size {\n\t\treturn nil, fmt.Errorf(\"githubapp: repository proof size mismatch\")\n\t}\n\treturn decoded, nil\n}\n\n// DoToken issues an authenticated GitHub REST call with an installation token and\n// returns the status + raw body for the caller to parse. It is the reusable\n// primitive the worker's PR opener builds the Git Data API flow on, so every\n// GitHub egress goes through the one SSRF-guarded client + fixed base host.","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L307-L343","documentation":"Wrapped decode error from GetFileContent: the repository-contents response downloaded fine but its JSON payload could not be unmarshalled into the proof struct (type/encoding/content/size fields). Included via %w so the underlying json error stays visible.","triggerScenarios":"A 200 body that is not the expected {type, encoding, content, size} object — e.g. HTML injected by a proxy with 200, truncated response, or GitHub schema change to the contents payload.","commonSituations":"Intercepting proxies/inspectors returning success pages; network truncation; API shape drift on /contents endpoint.","solutions":["Log the raw response body and unwrap with errors.As (*json.SyntaxError / *json.UnmarshalTypeError)","Bypass proxies and call api.github.com directly to isolate middlebox interference","Compare the payload against the GitHub contents-API schema and update the struct if changed","Retry on transient truncation; persist raw bytes for postmortem if it recurs"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"var syn *json.SyntaxError\nif errors.As(err, &syn) {\n    log.Printf(\"contents payload not JSON (offset %d) — bypass proxy and retry\", syn.Offset)\n} else {\n    return fmt.Errorf(\"contents schema drift: %w\", err)\n}","preventionTips":["Avoid proxies that alter api.github.com responses","Log raw response bytes on decode errors","Re-verify struct tags against the contents-API schema after GitHub API changes"],"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"}