@octokit/rest
semver
>=19.0.0 <23.0.0postconditions50functions49last verified2026-04-13Postconditions: what we check
- repos.get · github-repo-get-no-try-catcherrorWhenoctokit.repos.get() called without try-catchThrows
RequestError with status 404 (not found), 403 (forbidden), 401 (unauthorized)Required handlingMUST wrap await octokit.repos.get() in try-catch block. Catch block should check error.status for specific error codes: 404 (repo not found/private), 403 (rate limit or permission denied), 401 (auth failed). Handle each case appropriately.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - repos.create · github-repo-create-no-try-catcherrorWhenoctokit.repos.create() called without try-catchThrows
RequestError with status 422 (validation failed), 403 (forbidden), 401 (unauthorized)Required handlingMUST wrap await octokit.repos.create() in try-catch block. Check error.status to distinguish: 422 (validation error - check error.message for details), 403 (quota/permission issue), 401 (authentication failure).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[2] - repos.update · github-repo-update-no-try-catcherrorWhenoctokit.repos.update() called without try-catchThrows
RequestError with status 404 (not found), 403 (forbidden), 422 (validation failed)Required handlingMUST wrap await octokit.repos.update() in try-catch block. Handle 404 (repo not found), 403 (insufficient permissions), 422 (invalid parameters).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[3] - repos.delete · github-repo-delete-no-try-catcherrorWhenoctokit.repos.delete() called without try-catchThrows
RequestError with status 404 (not found), 403 (forbidden), 401 (unauthorized)Required handlingMUST wrap await octokit.repos.delete() in try-catch block. Always verify repository exists before deletion. Handle 403 (verify admin permissions), 404 (already deleted or never existed), 401 (auth issue).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[4] - git.getRef · github-git-getref-no-try-catcherrorWhenoctokit.git.getRef() called without try-catchThrows
RequestError with status 404 (ref not found), 403 (forbidden), 401 (unauthorized)Required handlingMUST wrap await octokit.git.getRef() in try-catch block. 404 errors are common and expected (ref doesn't exist), so handle gracefully. Also handle 403 (private repo or rate limit) and 401 (auth failure).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[5] - git.createRef · github-git-createref-no-try-catcherrorWhenoctokit.git.createRef() called without try-catchThrows
RequestError with status 422 (ref already exists), 404 (repo not found), 403 (forbidden)Required handlingMUST wrap await octokit.git.createRef() in try-catch block. Handle 422 (ref already exists - check if this is acceptable), 404 (repo doesn't exist), 403 (no write access). Consider checking if ref exists first with git.getRef().costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[6] - pulls.create · github-pull-create-no-try-catcherrorWhenoctokit.pulls.create() called without try-catchThrows
RequestError with status 422 (validation failed), 403 (forbidden), 404 (repo not found)Required handlingMUST wrap await octokit.pulls.create() in try-catch block. Check error.status and error.message: 422 can indicate "No commits between base and head", "Head ref doesn't exist", or "A pull request already exists". Handle each case appropriately.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[7] - pulls.merge · github-pull-merge-no-try-catcherrorWhenoctokit.pulls.merge() called without try-catchThrows
RequestError with status 405 (not mergeable), 404 (not found), 403 (forbidden)Required handlingMUST wrap await octokit.pulls.merge() in try-catch block. Before merging, check PR mergeable state. Handle 405 (check error.message for specific reason: conflicts, required checks, already merged), 404 (PR not found), 403 (no permission).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[8] - pulls.list · github-pull-list-no-try-catchwarningWhenoctokit.pulls.list() called without try-catchThrows
RequestError with status 404 (repo not found), 403 (forbidden), 422 (invalid params)Required handlingSHOULD wrap await octokit.pulls.list() in try-catch block. Handle 404 (repo not found or private), 403 (check rate limit headers), 422 (validate query parameters).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[9] - issues.create · github-issue-create-no-try-catcherrorWhenoctokit.issues.create() called without try-catchThrows
RequestError with status 422 (validation failed), 403 (forbidden), 404 (repo not found), 410 (issues disabled)Required handlingMUST wrap await octokit.issues.create() in try-catch block. Handle 422 (validation - check error.message for details), 403 (no permission), 404 (repo not found), 410 (issues disabled - direct user to discussions or PRs instead).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[10] - issues.update · github-issue-update-no-try-catcherrorWhenoctokit.issues.update() called without try-catchThrows
RequestError with status 404 (not found), 403 (forbidden), 422 (validation failed), 410 (issues disabled)Required handlingMUST wrap await octokit.issues.update() in try-catch block. Handle 404 (issue not found), 403 (check if issue is locked or user lacks permission), 422 (invalid update parameters), 410 (issues disabled).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[11] - issues.list · github-issue-list-no-try-catchwarningWhenoctokit.issues.list() called without try-catchThrows
RequestError with status 404 (repo not found), 403 (forbidden), 422 (invalid params)Required handlingSHOULD wrap await octokit.issues.list() in try-catch block. Handle 404 (repo not found or private), 403 (check rate limit headers), 422 (validate filter/sort parameters).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[12] - repos.createOrUpdateFileContents · github-file-update-no-try-catcherrorWhenoctokit.repos.createOrUpdateFileContents() called without try-catchThrows
RequestError with status 404 (repo/branch not found), 409 (conflict), 422 (validation failed)Required handlingMUST wrap await octokit.repos.createOrUpdateFileContents() in try-catch block. Handle 409 (concurrent modification - fetch latest SHA and retry), 404 (verify repo and branch exist), 422 (validate commit message and content encoding).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[13] - repos.getContent · github-get-content-no-try-catcherrorWhenoctokit.repos.getContent() called without try-catchThrows
RequestError with status 404 (not found), 403 (forbidden), 403 (too large)Required handlingMUST wrap await octokit.repos.getContent() in try-catch block. Handle 404 (path not found - this is often expected behavior for existence checks), 403 with "too large" (use git.getBlob() for large files), 403 for other reasons (auth/rate limit).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[14] - search.repos · search-repos-rate-limiterrorWhenoctokit.search.repos() called without try-catch and rate limit (HTTP 403/429) is hit from exceeding 30 authenticated or 10 unauthenticated requests/minuteThrows
RequestError with status 403 (rate limit exceeded) or 429 (secondary rate limit). Response headers include x-ratelimit-remaining: 0 and x-ratelimit-reset. Secondary rate limits are undocumented but trigger at rapid burst patterns.Required handlingMUST wrap await octokit.search.repos() in try-catch. Check error.status === 403 and error.response?.headers['x-ratelimit-remaining'] === '0' for rate limit. Implement exponential backoff. Consider @octokit/plugin-throttling plugin.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[15] - search.repos · search-repos-validation-errorwarningWhenoctokit.search.repos() called with query exceeding 256 characters or more than 5 AND/OR/NOT operators, or querying inaccessible resourcesThrows
RequestError with status 422 (Validation failed). Also 503 (Service Unavailable) when query times out server-side.Required handlingMUST wrap in try-catch. Validate query length (<256 chars) before calling. Handle 422 (invalid query — show user a helpful error), 503 (search timeout — retry with simpler query).costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[15] - search.code · search-code-auth-requirederrorWhenoctokit.search.code() called without authentication or with invalid tokenThrows
RequestError with status 401 (Requires authentication) for unauthenticated requests. Code search requires authentication — unlike other search endpoints.Required handlingMUST wrap in try-catch. Handle 401 (missing/invalid auth — check token configuration), 403 (rate limit — 9/min limit is easy to hit), 422 (invalid query syntax). Verify octokit instance has auth token before calling.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[15] - search.issuesAndPullRequests · search-issues-rate-limiterrorWhenoctokit.search.issuesAndPullRequests() called without try-catch and hits 30/min rate limit or 10/min semantic search limitThrows
RequestError with status 403 or 429 (rate limit exceeded).Required handlingMUST wrap in try-catch. Implement exponential backoff on 403/429. Check x-ratelimit-remaining headers. Consider using octokit.paginate() with throttling plugin for bulk operations.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[15] - git.createCommit · git-create-commit-not-founderrorWhenoctokit.git.createCommit() called without try-catch and the repo, tree SHA, or parent commit SHA does not existThrows
RequestError with status 404 (Not Found) when owner/repo does not exist or the token lacks access. RequestError with status 409 (Conflict) when parent commit references are invalid or SHA collision.Required handlingMUST wrap in try-catch. Handle 404 (repo not found or no access), 409 (conflict — re-fetch latest commit SHA and retry), 422 (validation — check tree SHA is valid). Always use the latest commit SHA as parent to avoid conflicts.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[16] - git.createTree · git-create-tree-invalid-shaerrorWhenoctokit.git.createTree() called without try-catch when base_tree SHA or blob SHAs in tree items are invalid or not found in the repositoryThrows
RequestError with status 404 (Not Found) when repo or base_tree SHA not found. RequestError with status 422 (Validation Failed) when tree items contain invalid modes, invalid SHAs, or exceed GitHub's file size limits.Required handlingMUST wrap in try-catch. Validate blob SHAs come from the same repository. Handle 404 (base_tree not found — use current HEAD SHA), 422 (invalid tree items — check file modes: 100644, 100755, 040000, 160000, 120000).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[17] - git.createBlob · git-create-blob-errorerrorWhenoctokit.git.createBlob() called without try-catch when repo not found, token lacks write access, or content exceeds file size limitsThrows
RequestError with status 403 (Forbidden — no write access or file too large for blob API — use uploads for files > 100MB). Status 404 (Not Found — repo or owner not found). Status 422 (Validation Failed).Required handlingMUST wrap in try-catch. Handle 403 (check token has contents:write scope), 404 (verify repo owner/name), 422 (validate base64 encoding and file size).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[18] - git.updateRef · git-update-ref-non-fast-forwarderrorWhenoctokit.git.updateRef() called without try-catch when the ref has been updated by another process (non-fast-forward update) or ref doesn't existThrows
RequestError with status 422 (Unprocessable Entity) for non-fast-forward updates when force is not set. Status 404 (Not Found) when ref doesn't exist. Status 409 (Conflict) in some concurrency scenarios.Required handlingMUST wrap in try-catch. Handle 422 (non-fast-forward — re-fetch HEAD, re-create tree/commit on top of new HEAD, retry). Handle 404 (ref not found — check branch name). This function MUST be wrapped or commit pipelines lose data.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[19] - checks.create · checks-create-not-github-apperrorWhenoctokit.checks.create() called without try-catch and the octokit instance uses OAuth token or PAT instead of GitHub App authenticationThrows
RequestError with status 403 (Forbidden). OAuth apps and personal access tokens (classic) cannot use this endpoint — only GitHub App installations can create check runs. GitHub Apps need the checks:write permission.Required handlingMUST wrap in try-catch. Handle 403 (verify using GitHub App installation token, not PAT/OAuth — check authentication method and checks:write permission). Handle 404 (repo not found), 422 (invalid check run parameters: invalid conclusion value, missing name/head_sha).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[20] - checks.update · checks-update-invalid-transitionwarningWhenoctokit.checks.update() called without try-catch with an invalid status transition or conclusion value, or non-App authenticationThrows
RequestError with status 403 (non-App auth) or 422 (invalid conclusion/status combination — e.g., setting status to "waiting"/"pending"/"requested" which is only allowed for GitHub Actions, not Apps).Required handlingMUST wrap in try-catch. Handle 403 (App auth required), 404 (check run not found — verify check_run_id), 422 (invalid status for App context — only use queued/ in_progress/completed with valid conclusion values like success/failure/neutral).costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[20] - actions.createWorkflowDispatch · workflow-dispatch-no-triggererrorWhenoctokit.actions.createWorkflowDispatch() called without try-catch when the workflow file lacks a workflow_dispatch: trigger or when repo/workflow not foundThrows
RequestError with status 404 (Not Found) when the workflow file does not exist or does not have a workflow_dispatch trigger defined. Also 422 when the ref (branch/tag) does not exist.Required handlingMUST wrap in try-catch. Handle 404 (workflow not found or lacks workflow_dispatch trigger — verify .github/workflows/<file>.yml has workflow_dispatch: trigger), 422 (invalid ref or input keys not defined in workflow), 403 (no actions:write permission).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[21] - repos.createRelease · create-release-tag-not-founderrorWhenoctokit.repos.createRelease() called without try-catch when tag doesn't exist, discussion_category_name is invalid, or secondary rate limit triggeredThrows
RequestError with status 404 (Not Found) when discussion_category_name is invalid. Status 422 (Validation Failed) when tag_name conflicts or validation fails. Secondary rate limit (403) from creating content too quickly.Required handlingMUST wrap in try-catch. Handle 404 (invalid discussion category — validate or omit discussion_category_name), 422 (tag conflict — check if release already exists for tag), 403 secondary rate limit (add delay between release creation and asset upload steps).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[22] - repos.createDeployment · create-deployment-conflicterrorWhenoctokit.repos.createDeployment() called without try-catch when required status checks have not passed or a merge conflict existsThrows
RequestError with status 409 (Conflict) when required status check contexts haven't succeeded or there's a merge conflict preventing the deployment. Status 422 (Validation Failed) when endpoint is spammed.Required handlingMUST wrap in try-catch. Handle 409 (check error.message — "required contexts" haven't passed: either set required_contexts: [] to bypass or wait for CI), 422 (validation), 202 response (not an error — auto-merge in progress, poll for completion). Always check error.message for actionable info on 409.costhighin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[23] - repos.createDeploymentStatus · create-deployment-status-not-founderrorWhenoctokit.repos.createDeploymentStatus() called without try-catch when the deployment_id doesn't exist in the repositoryThrows
RequestError with status 404 (Not Found) when deployment_id is invalid, or the deployment was deleted. Status 422 (Validation Failed) for invalid state values.Required handlingMUST wrap in try-catch. Store deployment_id immediately after createDeployment(). Handle 404 (deployment deleted — log and skip status update), 422 (invalid state — only use: error/failure/inactive/in_progress/queued/pending/success).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[24] - repos.createCommitStatus · create-commit-status-not-foundwarningWhenoctokit.repos.createCommitStatus() called without try-catch when the commit SHA doesn't exist or token lacks repo:status scopeThrows
RequestError with status 404 (Not Found) when owner/repo doesn't exist or commit SHA is not found. Status 422 (Validation Failed) when state is not one of pending/success/failure/error.Required handlingSHOULD wrap in try-catch. Handle 404 (invalid SHA — use full 40-char SHA, verify commit exists), 422 (invalid state — only use pending/success/failure/error), 403 (token lacks repo:status scope).costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[25] - pulls.get · pulls-get-not-foundwarningWhenoctokit.pulls.get() called without try-catch when pull_number doesn't exist or token lacks repo accessThrows
RequestError with status 404 (Not Found) when PR doesn't exist, was converted to draft, or token lacks access to the private repository.Required handlingSHOULD wrap in try-catch. Handle 404 (PR not found — may be normal in webhook processors if PR was deleted), 403 (no access to private repo).costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[26] - pulls.requestReviewers · pulls-request-reviewers-invalidwarningWhenoctokit.pulls.requestReviewers() called without try-catch when reviewers are not collaborators, team doesn't exist, or PR is already closed/mergedThrows
RequestError with status 422 (Unprocessable Entity) when a requested reviewer is not a collaborator on the repo, or team_slugs contains a non-existent team. Also 422 when requesting review from the PR author.Required handlingSHOULD wrap in try-catch. Handle 422 (invalid reviewer — check error.message for which user/team is invalid, verify collaborator status before requesting), 404 (PR not found), 403 (no write access).costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[27] - issues.createComment · issues-create-comment-not-founderrorWhenoctokit.issues.createComment() called without try-catch when issue/PR doesn't exist, is locked, or issues are disabled for the repositoryThrows
RequestError with status 404 (Not Found) when issue_number doesn't exist. Status 403 (Forbidden) when issue is locked. Status 410 (Gone) when issues are disabled for the repository.Required handlingMUST wrap in try-catch. Handle 403 (issue locked — log and skip silently), 404 (issue/PR not found — may have been deleted), 410 (issues disabled for repo — fallback to PR comment API for PRs). Check error.status and handle each case gracefully.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[28] - issues.addLabels · issues-add-labels-not-foundwarningWhenoctokit.issues.addLabels() called without try-catch when a label doesn't exist in the repository or the issue doesn't existThrows
RequestError with status 404 (Not Found) when the issue_number doesn't exist or when a label in the labels array doesn't exist in the repository. Status 410 (Gone) when issues are disabled.Required handlingSHOULD wrap in try-catch. Handle 404 (label not found — create the label first with issues.createLabel(), or verify label exists), 410 (issues disabled), 403 (no write access). Consider creating required labels as part of repo setup.costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[29] - users.getAuthenticated · users-get-authenticated-no-autherrorWhenoctokit.users.getAuthenticated() called without try-catch when the token is invalid, expired, or revokedThrows
RequestError with status 401 (Requires authentication) when called without an auth token. Status 403 (Forbidden) when the token has insufficient scope (fine-grained tokens without user read permission).Required handlingMUST wrap in try-catch. Handle 401 (no/invalid token — check GITHUB_TOKEN env var or token rotation), 403 (insufficient scope — verify token has required scopes for your use case). Log the error and exit gracefully.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[30] - orgs.getMembershipForUser · org-membership-not-foundwarningWhenoctokit.orgs.getMembershipForUser() called without try-catch when the user is not a member, org doesn't exist, or token lacks org:read permissionThrows
RequestError with status 404 (Not Found) when the user is not a member of the organization. Status 403 (Forbidden) when the token lacks permission to view organization membership.Required handlingMUST wrap in try-catch. Treat 404 as "user is not a member" (not an error). Handle 403 (token lacks org read permission — request read:org scope), 404 (not a member — return false/deny access). Do NOT re-throw 404 errors from membership checks — they are expected non-member responses.costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[31] - paginate · paginate-rate-limiterrorWhenoctokit.paginate() called without try-catch on a large list that requires many pages, hitting the rate limit mid-paginationThrows
RequestError with status 403 (Forbidden) or 429 (Too Many Requests) when the pagination exceeds the rate limit mid-traversal. The partial results accumulated so far are lost when the error is thrown.Required handlingMUST wrap in try-catch. Use @octokit/plugin-throttling to automatically handle rate limits during pagination. Handle 403 (rate limit — check x-ratelimit-remaining, back off and resume). Consider using octokit.paginate.iterator() for streaming to process pages as they arrive.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[32] - pulls.createReview · pulls-create-review-no-try-catcherrorWhenoctokit.pulls.createReview() called without try-catch when the PR is not found, the review body violates spam detection, or permission is insufficientThrows
RequestError with status 403 (Forbidden — insufficient permissions or non-collaborator attempting to review), 404 (Not Found — PR or repo not found), 422 (Validation Failed — invalid event type, comment body violates spam detection, or endpoint has been spammed too rapidly).Required handlingMUST wrap in try-catch. Handle 403 (check token has pull-requests:write scope), 404 (verify PR number and repo owner/name), 422 (invalid event type — only PENDING/APPROVE/REQUEST_CHANGES/COMMENT are valid; backoff if spam detection hit).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[33] - pulls.submitReview · pulls-submit-review-wrong-stateerrorWhenoctokit.pulls.submitReview() called without try-catch when the review is not in PENDING state, the review ID is invalid, or event parameter is missingThrows
RequestError with status 422 (Validation Failed — review is not PENDING, event parameter is blank/invalid, or endpoint has been spammed), 404 (Not Found — review_id or pull_number not found in repository).Required handlingMUST wrap in try-catch. Handle 422 (verify review is in PENDING state before submitting — use pulls.getReview() to check; ensure event parameter is provided). Handle 404 (verify review_id and pull_number exist). Track review state to avoid double-submit on retry.costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[33] - repos.uploadReleaseAsset · release-asset-duplicate-filenameerrorWhenoctokit.repos.uploadReleaseAsset() called without try-catch when an asset with the same filename already exists on the releaseThrows
RequestError with status 422 (Unprocessable Entity) when a file with the same name is already attached to the release. GitHub does not overwrite — the duplicate upload fails. Must delete the existing asset first.Required handlingMUST wrap in try-catch. Handle 422 (check if asset already exists with repos.listReleaseAssets(), delete it with repos.deleteReleaseAsset() before re-uploading). Handle 404 (verify release_id from createRelease response). Note: filename must match the Content-Type header; GitHub renames files with special characters automatically.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[34] - repos.addCollaborator · add-collaborator-emu-accountwarningWhenoctokit.repos.addCollaborator() called without try-catch when the target user is an Enterprise Managed User (EMU) being added to a non-enterprise repository, or validation fails due to invalid permission levelThrows
RequestError with status 422 (Validation Failed) when an EMU account is invited to a repository in an enterprise with personal user accounts, or when the assigned permission level is below the organization's base permission. Status 403 (Forbidden) when the authenticated user lacks admin access to the repository.Required handlingMUST wrap in try-catch. Handle 422 (check for EMU constraints if your org uses GitHub Enterprise; verify permission level is not below org base permission). Handle 403 (verify authenticated user has admin role on the repository). Note: 201 means invitation sent; 204 means user was already a collaborator. Check the response status to distinguish.costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[35] - repos.createWebhook · create-webhook-invalid-configerrorWhenoctokit.repos.createWebhook() called without try-catch when the webhook URL is unreachable/malformed, or the repository does not existThrows
RequestError with status 422 (Validation Failed) when the webhook URL is malformed, uses a disallowed scheme, or points to a GitHub-internal address. Status 403 (Forbidden) when the authenticated user lacks admin access to the repository. Status 404 (Not Found) when the repository doesn't exist.Required handlingMUST wrap in try-catch. Handle 422 (validate URL is publicly reachable HTTPS endpoint; check for localhost/private IP disqualifiers). Handle 403 (verify token has admin:repo_hook scope or the GitHub App has the Webhooks read-write permission). Handle 404 (verify repo owner and name before attempting webhook creation).costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[36] - repos.createFork · create-fork-async-not-awaitedwarningWhenoctokit.repos.createFork() response is used immediately after the call without waiting for the async fork process to completeThrows
Does not throw, but the fork's git objects are not immediately available. Subsequent git operations on the fork (clone, push) within seconds of the 202 response may fail. For forks taking > 5 minutes, GitHub Support must be contacted.Required handlingMUST wrap in try-catch. Handle 403 (permission denied or forking disabled for org), 422 (fork already exists for this user — check if target fork already exists), 400 (invalid parameters). After successful 202, wait before using the fork: implement exponential backoff polling of repos.get() on the fork to confirm availability before proceeding.costmediumin prodsilent failureusers seedegraded performancevisibilityvisibleSources[37] - git.createTag · git-create-tag-without-create-refwarningWhenoctokit.git.createTag() called without a subsequent git.createRef() call to make the tag reference visible, or called without try-catchThrows
RequestError with status 422 (Validation Failed) when the SHA of the tagged object is invalid or references a non-existent object. Status 409 (Conflict) for concurrency issues during tag creation.Required handlingMUST wrap in try-catch. Handle 422 (invalid SHA — verify the object SHA exists in the repo before tagging), 409 (retry with backoff for concurrency conflicts). IMPORTANT: Always follow createTag() with git.createRef('refs/tags/<name>', sha) using the sha from the createTag response to make the tag visible.costmediumin prodsilent failureusers seedegraded performancevisibilityvisibleSources[38] - git.deleteRef · git-delete-ref-default-brancherrorWhenoctokit.git.deleteRef() called without try-catch when the ref is the default branch, the ref format is invalid, or concurrency conflict occursThrows
RequestError with status 422 (Validation Failed) when attempting to delete the repository's default branch (GitHub blocks this), when the ref format is wrong (must be 'heads/<name>' not 'refs/heads/<name>'), or spam detection triggers. Status 409 (Conflict) for concurrent deletion attempts.Required handlingMUST wrap in try-catch. Handle 422 (check ref is not default branch — compare with repos.get().default_branch before deleting; ensure ref format is 'heads/<name>' not 'refs/heads/<name>'). Handle 409 (retry with backoff). Note: 404 is NOT returned for missing refs — use git.getRef() first to verify existence if needed.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[19] - actions.cancelWorkflowRun · cancel-workflow-run-terminal-statewarningWhenoctokit.actions.cancelWorkflowRun() called without try-catch when the workflow run is already in a terminal state (completed, cancelled, failed, timed_out)Throws
RequestError with status 409 (Conflict) when the workflow run cannot be cancelled because it has already reached a terminal state. The 202 success response means cancellation was ACCEPTED, not that it has completed.Required handlingMUST wrap in try-catch. Handle 409 (workflow is already in a terminal state — check run status with actions.getWorkflowRun() before cancelling; treat 409 as success if the goal is to ensure the run is not running). Handle 404 (run_id not found — verify run exists). Poll actions.getWorkflowRun() after 202 to confirm cancellation completes.costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[39] - pulls.update · pulls-update-invalid-basewarningWhenoctokit.pulls.update() called without try-catch when setting the base to a non-existent branch, updating a merged PR's state, or lacking write permissionsThrows
RequestError with status 422 (Validation Failed) when the new base branch does not exist in the repository, when attempting to reopen a merged PR (merged PRs cannot be reopened), or when validation fails on the body/title parameters. Status 403 (Forbidden) when the token lacks pull-requests:write permission.Required handlingMUST wrap in try-catch. Handle 422 (verify base branch exists before retargeting; check PR is not in merged state before changing state). Handle 403 (verify token has pull-requests:write scope). Handle 404 (verify PR number and repo).costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[26] - apps.createInstallationAccessToken · apps-create-installation-token-no-try-catcherrorWhenoctokit.apps.createInstallationAccessToken() called without try-catch when the JWT used to authenticate is expired, the App's private key has been rotated, the installation has been suspended, or the installation_id is invalid.Throws
RequestError with status 401 (Bad credentials) when the JWT is expired (JWTs are valid for 10 minutes max), malformed, or signed with a rotated private key. Status 403 (Forbidden) when the installation has been suspended or the App has been blocked by the org. Status 404 (Not Found) when the installation_id does not exist or is no longer accessible to this App. Status 422 when requested permissions exceed those granted to the installation.Required handlingMUST wrap in try-catch. Handle 401 (mint a fresh JWT and retry once; if it persists, surface a config error to alert that the App private key is invalid or rotated). Handle 403 (do NOT retry; surface to the customer that their installation is suspended). Handle 404 (treat as uninstall; remove the org from the database and stop scheduled jobs against it). Handle 422 (surface as a permissions mismatch; do not loop). Never silently swallow.costhighin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - repos.compareCommitsWithBasehead · repos-compare-commits-basehead-no-try-catcherrorWhenoctokit.repos.compareCommitsWithBasehead() called without try-catch when either ref does not exist, the diff exceeds GitHub's response limits, or the token lacks read access to the repository.Throws
RequestError with status 404 (Not Found) when one of the refs in the basehead parameter (format "{base}...{head}") does not exist in the repo, when the repo is private and the token lacks access, or when the repo was renamed/transferred. Status 422 (Unprocessable Entity) when the basehead format is invalid or the two refs are not comparable (different unrelated history). Status 403 with a rate-limit message when the diff is too large; GitHub caps the response at 300 files / 1MB and very large monorepo diffs can hit this.Required handlingMUST wrap in try-catch. Handle 404 (verify both refs still exist; a deleted or force-pushed branch will not be re-fetchable, so surface a clean error to the bot rather than retrying). Handle 422 (verify basehead is "{base}...{head}" and both refs share history). Handle large-diff 403 by falling back to paginated fetch with per_page=100 and assembling the file list across pages.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[42] - issues.removeLabel · issues-remove-label-no-try-catchwarningWhenoctokit.issues.removeLabel() called without try-catch when the label is not currently attached to the issue (race with concurrent automations), when the issue has been locked or moved, or when the token lacks issues:write.Throws
RequestError with status 404 (Not Found) when the named label is not currently applied to the issue. This is the dominant failure mode in multi-bot environments where two automations race to remove the same label. Status 410 (Gone) when the issue has been deleted. Status 403 (Forbidden) when the token lacks issues:write scope or the repository has issues disabled. Status 301 (Moved Permanently) when the repo has been renamed and the client did not follow the redirect.Required handlingMUST wrap in try-catch. Treat 404 as a no-op (the label is already gone; the desired end state is satisfied). Handle 410 by removing the issue from the work queue (it is deleted). Handle 403 by surfacing a permissions error rather than retrying. Never silently swallow 5xx.costlowin prodimmediate exceptionusers seedegraded performancevisibilitysilentSources[43] - pulls.dismissReview · pulls-dismiss-review-no-try-catchwarningWhenoctokit.pulls.dismissReview() called without try-catch when the review is not in a dismissable state (already dismissed, or is a PENDING review by another reviewer), the PR is closed/merged, or the token lacks pull-requests:write.Throws
RequestError with status 422 (Unprocessable Entity) when the review is already in DISMISSED state, is PENDING (only the author can dismiss their own pending review), or when dismissing would violate branch protection rules that require a re-review. Status 403 (Forbidden) when the token lacks pull-requests:write or when branch protection prohibits dismissals from non-admins. Status 404 (Not Found) when the review_id does not exist or the PR has been deleted from a force-deleted branch.Required handlingMUST wrap in try-catch. Treat 422 as a no-op when the review is already DISMISSED (desired state reached). Surface 403 to the operator rather than retrying; it indicates a branch-protection policy mismatch that needs manual review. Handle 404 by skipping the PR. Never silently swallow.costmediumin prodimmediate exceptionusers seedegraded performancevisibilitysilentSources[44]
Sources
Every postcondition cites at least one of these. Grouped by source type; numbered to match the footnotes above.
Official documentation
- [2]docs.github.com/en/rest/reposRepos
- [3]docs.github.com/en/rest/reposRepos
- [4]docs.github.com/en/rest/reposRepos
- [5]docs.github.com/en/rest/gitRefs
- [6]docs.github.com/en/rest/gitRefs
- [7]docs.github.com/en/rest/pullsPulls
- [8]docs.github.com/en/rest/pullsPulls
- [9]docs.github.com/en/rest/pullsPulls
- [10]docs.github.com/en/rest/issuesIssues
- [11]docs.github.com/en/rest/issuesIssues
- [12]docs.github.com/en/rest/issuesIssues
- [13]docs.github.com/en/rest/reposContents
- [14]docs.github.com/en/rest/reposContents
- [15]docs.github.com/en/rest/searchSearch
- [16]docs.github.com/en/rest/gitCommits
- [17]docs.github.com/en/rest/gitTrees
- [18]docs.github.com/en/rest/gitBlobs
- [19]docs.github.com/en/rest/gitRefs
- [20]docs.github.com/en/rest/checksRuns
- [21]docs.github.com/en/rest/actionsWorkflows
- [22]docs.github.com/en/rest/releasesReleases
- [23]docs.github.com/en/rest/deploymentsDeployments
- [24]docs.github.com/en/rest/deploymentsStatuses
- [25]docs.github.com/en/rest/commitsStatuses
- [26]docs.github.com/en/rest/pullsPulls
- [27]docs.github.com/en/rest/pullsReview Requests
- [28]docs.github.com/en/rest/issuesComments
- [29]docs.github.com/en/rest/issuesLabels
- [30]docs.github.com/en/rest/usersUsers
- [31]docs.github.com/en/rest/orgsMembers
- [33]docs.github.com/en/rest/pullsReviews
- [34]docs.github.com/en/rest/releasesAssets
- [35]docs.github.com/en/rest/collaboratorsCollaborators
- [36]docs.github.com/en/rest/reposWebhooks
- [37]docs.github.com/en/rest/reposForks
- [38]docs.github.com/en/rest/gitTags
- [39]docs.github.com/en/rest/actionsWorkflow Runs
- [40]docs.github.com/en/rest/appsApps
- [41]docs.github.com/en/apps/creating-github-appsGenerating An Installation Access Token For A Github App
- [42]docs.github.com/en/rest/commitsCommits
- [43]docs.github.com/en/rest/issuesLabels
- [44]docs.github.com/en/rest/pullsReviews
Source code
- [1]github.com/octokit/octokit.js/discussionsoctokit/octokit.js
- [32]github.com/octokit/plugin-paginate-rest.jsoctokit/plugin-paginate-rest.js
Research notes
Curator notes from SOURCES.md captured when the profile was written so you can verify the reasoning, not just the rules.
Sources for @octokit/rest Contract
This document lists all sources used to create the Nark profile for @octokit/rest.
Official Documentation
Error Handling
-
How to handle errors · octokit/octokit.js · Discussion #2039
- URL: https://github.com/octokit/octokit.js/discussions/2039
- Key Info: Official guidance on error handling patterns, RequestError properties
- Date Accessed: 2026-02-25
- Relevance: Primary source for error handling requirements
-
GitHub - octokit/request-error.js
- URL: https://github.com/octokit/request-error.js/
- Key Info: RequestError class documentation, properties (status, message, request, response)
- Date Accessed: 2026-02-25
- Relevance: Defines the error object structure returned by all @octokit/rest methods
API Documentation
-
@octokit/rest - npm
- URL: https://www.npmjs.com/package/@octokit/rest
- Key Info: Package overview, installation, basic usage
- Date Accessed: 2026-02-25
- Relevance: Official package documentation
-
GitHub REST API - Repositories
- URL: https://docs.github.com/en/rest/repos/repos
- Key Info: Repository operations (get, create, update, delete)
- Date Accessed: 2026-02-25
- Relevance: Documents expected status codes and error scenarios
-
GitHub REST API - Git References
- URL: https://docs.github.com/en/rest/git/refs
- Key Info: Git reference operations (getRef, createRef)
- Date Accessed: 2026-02-25
- Relevance: Documents ref operations and error cases
-
GitHub REST API - Pull Requests
- URL: https://docs.github.com/en/rest/pulls/pulls
- Key Info: Pull request operations (create, list, merge)
- Date Accessed: 2026-02-25
- Relevance: Documents PR operations and mergeable state errors
-
GitHub REST API - Issues
- URL: https://docs.github.com/en/rest/issues/issues
- Key Info: Issue operations (create, update, list)
- Date Accessed: 2026-02-25
- Relevance: Documents issue operations and error codes (410 for disabled issues)
-
GitHub REST API - Repository Contents
- URL: https://docs.github.com/en/rest/repos/contents
- Key Info: File content operations (getContent, createOrUpdateFileContents)
- Date Accessed: 2026-02-25
- Relevance: Documents file size limits, SHA conflicts, error scenarios
Real-World Usage
Backstage
- File:
test-repos/backstage/plugins/catalog-import/src/api/GitHub.ts - Pattern: Uses
.catch(e => throw new Error())on each API call - Key Methods: repos.get(), git.getRef(), git.createRef(), repos.createOrUpdateFileContents(), pulls.create()
- Error Handling: Expects
error.statusanderror.messageproperties - Date Analyzed: 2026-02-25
Security Analysis
CVE Search Results
- Search Date: 2026-02-25
- Finding: No major CVEs found for @octokit/rest
- Package Health:
- 5.6M+ weekly downloads
- Actively maintained (4 maintainers)
- Regular version updates
- Versions analyzed: v19-22
Key Behavioral Patterns
Error Object Structure
All errors thrown by @octokit/rest are instances of RequestError with:
status: HTTP status code (404, 403, 422, etc.)message: Error message from GitHub APIrequest: Request details (method, url, headers, body)response: Response details (url, status, headers, data)
Common Error Codes
- 404 Not Found: Resource doesn't exist, or repo is private with insufficient access
- 403 Forbidden: Rate limit exceeded, or insufficient permissions
- 401 Unauthorized: Invalid or missing authentication token
- 422 Unprocessable Entity: Validation errors (duplicate name, ref already exists, invalid params)
- 409 Conflict: SHA mismatch on file updates (concurrent modification)
- 405 Method Not Allowed: Operation not permitted (e.g., PR not mergeable)
- 410 Gone: Feature disabled (e.g., issues disabled for repository)
Rate Limiting
- GitHub API has rate limits (5000/hour authenticated, 60/hour unauthenticated)
- Rate limit errors return 403 status with specific headers
- Recommendation: Use
@octokit/plugin-throttlingfor automatic retry handling
Authentication Patterns
- Instance created with auth token:
new Octokit({ auth: token }) - 404 errors can indicate private repos (authentication ambiguity)
- 401 errors indicate invalid/missing authentication
Contract Design Decisions
Severity Levels
- ERROR: All write operations (create, update, delete) and critical read operations (get, getRef, getContent)
- WARNING: List operations (pulls.list, issues.list) - less critical but should still handle errors
Detector Strategy
- Pattern:
octokit.<resource>.<method>()orinstance.<resource>.<method>() - Requires:
awaitwithout surroundingtry-catchblock - Instance detection: Need to track variable assignments from
new Octokit()
Coverage
Contract covers most common operations:
- Repository operations (6 methods)
- Git operations (2 methods)
- Pull request operations (3 methods)
- Issue operations (3 methods)
- File operations (2 methods)
Out of Scope
Not covered in v1.0.0 (may add in future versions):
- Gist operations
- User operations
- Organization operations
- Team operations
- Webhook operations
- Search operations
- Rate limit checking
Validation Notes
Fixture Requirements
- proper-error-handling.ts: Demonstrate correct try-catch usage
- missing-error-handling.ts: Show violations (no try-catch)
- instance-usage.ts: Test instance-based detection
Expected Analyzer Behavior
- Must detect instance methods:
octokit.repos.get() - Must detect 2-level property chains:
<instance>.repos.get() - Must verify try-catch wrapping
- Must handle both direct imports and instance assignments
Related Packages
@octokit/request-error: Error class used by @octokit/rest@octokit/plugin-throttling: Plugin for automatic rate limit handling@octokit/core: Core Octokit functionality
Changelog
v1.0.0 (2026-02-25)
- Initial contract covering 16 common API methods
- Focus on repository, git, pull request, issue, and file operations
- Severity: ERROR for write operations, WARNING for list operations
- Sources: Official docs, real-world usage (backstage), no major CVEs found
Need a different package?
Request a profile