{"record":{"id":"aca48e6215e8fe32","repo":"JuliusBrussee/caveman","slug":"githubapp-installation-id-must-be-positive","errorCode":null,"errorMessage":"githubapp: installation id must be positive","messagePattern":"githubapp: installation id must be positive","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":160,"sourceCode":"\tToken     string    `json:\"token\"`\n\tExpiresAt time.Time `json:\"expires_at\"`\n}\n\n// Installation is the App-authenticated identity GitHub assigns to an install.\n// Callers use it to reject callback-supplied ids that do not belong to this App.\ntype Installation struct {\n\tID      int64 `json:\"id\"`\n\tAccount struct {\n\t\tLogin string `json:\"login\"`\n\t\tID    int64  `json:\"id\"`\n\t} `json:\"account\"`\n}\n\n// GetInstallation verifies an installation id against GitHub using the App JWT.\nfunc (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\")","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L142-L178","documentation":"GetInstallation validates the installation ID before doing any I/O. A GitHub App installation ID is an int64 that GitHub always assigns as a positive number, so a non-positive value can never be valid. The library fails closed with this error instead of making a doomed network call.","triggerScenarios":"Calling App.GetInstallation(ctx, id) with id <= 0, e.g. an unset/zero-valued int64 from config, a failed strconv.ParseInt that fell back to 0, or a record where the installation ID was never populated.","commonSituations":"Config struct fields defaulting to 0 when the GitHub App ID env var is missing; database rows with a NULL/0 installation_id; confusion between the GitHub App ID and the installation ID; parsing \"0\" from CI variables.","solutions":["Check where the installation ID originates and ensure it is parsed/loaded before the call; log it just before GetInstallation","If it comes from an env var or config, fail fast at startup when it is missing or <= 0","Fix parsing code to propagate the strconv error instead of defaulting to 0","Confirm you are using the installation ID (from /app/installations or the webhook payload), not the App ID"],"exampleFix":"// before\nid := cfg.InstallationID // zero value\ninst, err := app.GetInstallation(ctx, id)\n// after\nif cfg.InstallationID <= 0 {\n\treturn fmt.Errorf(\"installation id not configured\")\n}\ninst, err := app.GetInstallation(ctx, cfg.InstallationID)","handlingStrategy":"validation","validationCode":"if installationID <= 0 {\n\treturn fmt.Errorf(\"installation id must be configured and positive, got %d\", installationID)\n}","typeGuard":"func validInstallationID(id int64) bool { return id > 0 }","tryCatchPattern":"inst, err := app.GetInstallation(ctx, id)\nif err != nil {\n\tif strings.Contains(err.Error(), \"installation id must be positive\") {\n\t\t// fix config/lookup before retrying\n\t}\n\treturn err\n}","preventionTips":["Validate the installation ID at config load/startup time","Propagate strconv.ParseInt errors instead of defaulting to 0","Distinguish App ID vs installation ID in your config naming"],"tags":["github-app","input-validation","go"],"backgroundTag":"invalid-argument-value","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"}