{"record":{"id":"b6fa95d8eef5664e","repo":"JuliusBrussee/caveman","slug":"githubapp-decode-token-response-w","errorCode":null,"errorMessage":"githubapp: decode token response: %w","messagePattern":"githubapp: decode token response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":221,"sourceCode":"\t\t}\n\t\tscopedPermissions[name] = level\n\t}\n\tjwt, err := a.AppJWT()\n\tif err != nil {\n\t\treturn InstallationToken{}, err\n\t}\n\tbody := map[string]any{\"permissions\": scopedPermissions, \"repositories\": []string{repository}}\n\tstatus, raw, err := a.do(ctx, \"Bearer \"+jwt, http.MethodPost,\n\t\t\"/app/installations/\"+strconv.FormatInt(installationID, 10)+\"/access_tokens\", body)\n\tif err != nil {\n\t\treturn InstallationToken{}, err\n\t}\n\tif status != http.StatusCreated {\n\t\treturn InstallationToken{}, fmt.Errorf(\"githubapp: mint token: HTTP %d: %s\", status, snippet(raw))\n\t}\n\tvar out InstallationToken\n\tif err := json.Unmarshal(raw, &out); err != nil {\n\t\treturn InstallationToken{}, fmt.Errorf(\"githubapp: decode token response: %w\", err)\n\t}\n\tif out.Token == \"\" {\n\t\treturn InstallationToken{}, fmt.Errorf(\"githubapp: token response carried no token\")\n\t}\n\treturn out, nil\n}\n\n// RevokeToken DELETEs /installation/token authenticated with the token itself —\n// the job-end \"drop all agency\" step. A best-effort revoke; the ~1h natural\n// expiry is the backstop.\nfunc (a *App) RevokeToken(ctx context.Context, token string) error {\n\tstatus, raw, err := a.do(ctx, \"Bearer \"+token, http.MethodDelete, \"/installation/token\", nil)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif status != http.StatusNoContent {\n\t\treturn fmt.Errorf(\"githubapp: revoke token: HTTP %d: %s\", status, snippet(raw))\n\t}","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L203-L239","documentation":"The access_tokens endpoint returned 201 but the body could not be decoded into the InstallationToken struct. The underlying json.Unmarshal error is wrapped with this prefix. Without a decodable response the library cannot return a usable token, so it fails.","triggerScenarios":"App.MintInstallationToken gets a 201 whose body is empty, HTML, or otherwise not the expected JSON shape — typically caused by proxies, misconfigured mock servers, or unexpected GitHub responses.","commonSituations":"Corporate TLS-inspecting proxies altering responses; test fixtures returning wrong-shaped JSON; GitHub API previews with changed payloads.","solutions":["Inspect the wrapped decode error and raw body to see what came back","Bypass or fix intermediary proxies that mangle API responses","Fix mock/fixture payloads to match the real access_tokens response (token, expires_at, permissions, repositories)","Update the library if GitHub's schema changed"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// No pre-call validation; ensure a clean network path to api.github.com","typeGuard":"func isDecodeErr(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"decode token response:\")\n}","tryCatchPattern":"tok, err := app.MintInstallationToken(ctx, id, []string{repo}, nil)\nif err != nil {\n\tif isDecodeErr(err) {\n\t\tlog.Printf(\"token response not parseable: %v\", err)\n\t\t// check proxy/mocks; retry once\n\t}\n\treturn err\n}","preventionTips":["Avoid TLS-intercepting proxies on api.github.com or pin expectations","Match mock fixtures to the real access_tokens response schema","Keep the library current with GitHub API changes"],"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"}