{"record":{"id":"7cfc72fe493e703a","repo":"JuliusBrussee/caveman","slug":"githubapp-token-response-carried-no-token","errorCode":null,"errorMessage":"githubapp: token response carried no token","messagePattern":"githubapp: token response carried no token","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":224,"sourceCode":"\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}\n\treturn nil\n}\n","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L206-L242","documentation":"The response decoded successfully but the token field was empty, meaning GitHub indicated success without actually issuing a credential. Since a tokenless response is useless and could indicate a broken flow, the library fails closed instead of returning an empty token.","triggerScenarios":"App.MintInstallationToken receiving a 201 whose JSON parses but has an empty or missing \"token\" field — e.g. a malformed fixture, an interception layer echoing a partial body, or an unexpected GitHub-side condition.","commonSituations":"Hand-written test doubles returning {\"expires_at\":\"...\"} without the token field; proxies stripping fields; API behavior changes.","solutions":["Fix the fixture/mock to include a non-empty token field","Log and inspect the raw response to confirm what GitHub returned","If the empty token persists against real GitHub, file an issue — treat it as an API anomaly"],"exampleFix":"// before\n{\"expires_at\": \"2026-01-01T00:00:00Z\"}\n// after\n{\"token\": \"ghs_xxx\", \"expires_at\": \"2026-01-01T00:00:00Z\"}","handlingStrategy":"try-catch","validationCode":"// No pre-call validation; guard the returned token before use instead","typeGuard":"func usableToken(t githubapp.InstallationToken) bool { return t.Token != \"\" }","tryCatchPattern":"tok, err := app.MintInstallationToken(ctx, id, []string{repo}, nil)\nif err != nil {\n\tif strings.Contains(err.Error(), \"carried no token\") {\n\t\t// log raw response; treat as upstream anomaly; retry once\n\t}\n\treturn err\n}\nif !usableToken(tok) { return fmt.Errorf(\"no token issued\") }","preventionTips":["Always check tok.Token != \"\" before storing or using it","Keep fixtures complete (include the token field)","Treat empty-token 201s as anomalies worth alerting on"],"tags":["github-app","empty-response","fail-closed"],"backgroundTag":"empty-api-response","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"}