Skip to content

fix: clarify missing repository errors#166

Open
charles-openclaw wants to merge 4 commits into
BeyteFlow:mainfrom
charles-openclaw:fix-repo-not-found-fallback
Open

fix: clarify missing repository errors#166
charles-openclaw wants to merge 4 commits into
BeyteFlow:mainfrom
charles-openclaw:fix-repo-not-found-fallback

Conversation

@charles-openclaw
Copy link
Copy Markdown

Summary

  • Return a clear Repository not found. Please check the URL and try again. fallback when GitHub returns 404 for a repository lookup.
  • Treat exhausted GitHub API rate limit responses as a retryable 429 instead of the generic auth/private-repo path.

Fixes #37

Verification

  • npm run lint
  • npx tsc --noEmit
  • git diff --check

I did not run npm run build; this change is limited to the Octokit error normalization path.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 30, 2026

@charles-openclaw is attempting to deploy a commit to the naheel0's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 820a480c-f130-4e0b-90c6-64f4507abf15

📥 Commits

Reviewing files that changed from the base of the PR and between 762b11b and 889aced.

📒 Files selected for processing (1)
  • src/lib/octokit.ts

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Better detection and clearer reporting when GitHub rate limits requests, returning a retryable 429 status and guidance to retry later.
    • More precise access error messages: distinguishes auth-required from repository-not-found and suggests verifying the repository URL.
    • More reliable branch/tree resolution when fetching repository snapshots, with additional resolution attempts and safe fallbacks.

Walkthrough

src/lib/octokit.ts adds a RATE_LIMITED error code and rate-limit detection (headers/message), refactors 403/404 mapping (403→AUTH_REQUIRED only without user token; 404→NOT_FOUND with "check the URL"), and resolves branch tree SHA before calling git.getTree.

Changes

API Error Handling & Branch Resolution

Layer / File(s) Summary
Rate limit detection and new error code
src/lib/octokit.ts
RepoAccessErrorCode adds "RATE_LIMITED". toRepoAccessError inspects error.response.headers (case-insensitive x-ratelimit-remaining, retry-after) and error.response.data.message, returning a RepoAccessError with status 429 and code "RATE_LIMITED" when rate limiting is detected.
Status-to-code mapping refactor
src/lib/octokit.ts
Refactors mapping so only 403 without a user access token returns AUTH_REQUIRED; 404 now returns NOT_FOUND with wording advising the caller to check the URL.
Branch-based tree SHA resolution
src/lib/octokit.ts
getRepoSnapshot attempts repos.getBranch(default_branch) to extract commit.commit.tree.sha, falls back to git.getCommit(commit.sha) for commit.tree.sha if needed, and finally calls git.getTree with tree_sha set to the resolved SHA or repoInfo.default_branch.

Sequence Diagram

sequenceDiagram
  participant Client
  participant GitHubAPI
  participant toRepoAccessError
  Client->>GitHubAPI: request (repos/git)
  GitHubAPI-->>Client: error response (status, headers, data.message)
  Client->>toRepoAccessError: pass error response
  toRepoAccessError-->>Client: RepoAccessError(status=429, code=RATE_LIMITED) when headers/message indicate rate limiting
Loading

🎯 4 (Complex) | ⏱️ ~45 minutes

"I nibble headers, listen for the freeze,
When GitHub sighs and traffic must cease,
I mark a four-two-nine and call it by name,
I tell the 404 to check the URL's frame,
A rabbit hops on, making errors tame. 🐇"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: clarify missing repository errors' is directly related to the main changes: improved error handling for 404 (NOT_FOUND) and rate limiting (RATE_LIMITED) scenarios.
Description check ✅ Passed The description clearly outlines two main objectives: handling 404 repository errors with user-friendly messaging and treating rate limits as retryable 429 responses, both directly related to the changeset.
Linked Issues check ✅ Passed The changes address all coding requirements from issue #37: detecting 404 errors with clear fallback messaging ('Repository not found. Please check the URL and try again.'), distinguishing rate-limit exhaustion (RATE_LIMITED with 429), and improving error detection logic.
Out of Scope Changes check ✅ Passed All modifications are focused on error normalization in the Octokit integration layer (RepoAccessErrorCode extension, toRepoAccessError updates, and getRepoSnapshot tree SHA resolution) directly supporting the linked objectives.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/lib/octokit.ts (1)

85-91: 💤 Low value

Consider adding a brief inline comment explaining the status code transformation.

The code intentionally returns HTTP 401 for a 403 response (when no user token is present) to trigger the authRequired UX path in the downstream route handler. This is a valid design choice, but the status code remapping could confuse future maintainers.

📝 Suggested comment
  if (status === 403 && !hasUserAccessToken) {
+   // Return 401 to trigger authRequired UX (login button) since the user may
+   // need to authenticate to access a private repository.
    return new RepoAccessError(
      "Repository not accessible. It may be private or unavailable. Log in with GitHub if you need access to a private repository.",
      401,
      "AUTH_REQUIRED",
    );
  }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/octokit.ts` around lines 85 - 91, Add a brief inline comment above
the RepoAccessError return in the code path that checks "if (status === 403 &&
!hasUserAccessToken)" explaining that a 403 from GitHub is intentionally
remapped to a 401 to trigger the downstream "authRequired" UX flow; reference
the RepoAccessError construction and the condition (status === 403 &&
!hasUserAccessToken) so future maintainers understand this status-code
transformation is deliberate and tied to the auth UX.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/lib/octokit.ts`:
- Around line 85-91: Add a brief inline comment above the RepoAccessError return
in the code path that checks "if (status === 403 && !hasUserAccessToken)"
explaining that a 403 from GitHub is intentionally remapped to a 401 to trigger
the downstream "authRequired" UX flow; reference the RepoAccessError
construction and the condition (status === 403 && !hasUserAccessToken) so future
maintainers understand this status-code transformation is deliberate and tied to
the auth UX.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d995afc7-d38e-4351-96d2-b1938a708537

📥 Commits

Reviewing files that changed from the base of the PR and between 0934fa8 and aedc701.

📒 Files selected for processing (1)
  • src/lib/octokit.ts

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@naheel0 naheel0 force-pushed the fix-repo-not-found-fallback branch from aedc701 to 56c5b8d Compare May 30, 2026 17:59
@naheel0 naheel0 requested a review from Copilot May 30, 2026 18:00
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@naheel0
Copy link
Copy Markdown
Member

naheel0 commented May 30, 2026

Summary of fix:\n- Resolve default_branch name to a tree SHA via
epos.getBranch before calling git.getTree (falls back if resolution fails).\n- Normalized header lookup (case-insensitive) and guarded response message handling.\n- Improved rate-limit detection (treats explicit 429 and checks x-ratelimit-remaining/
etry-after) and preserved RATE_LIMITED error code.\n- Changed the numeric status for the unauthenticated-access case to 403 while keeping code AUTH_REQUIRED for callers to handle.\n\nWhy: the previous code passed a branch name as ree_sha (which can cause getTree to fail) and had brittle header/status handling that resulted in misleading errors.\n\nSuggested tests to add:\n- Unit tests for oRepoAccessError mapping: 404 -> NOT_FOUND, 401 -> AUTH_REQUIRED, 429/403 rate-limit -> RATE_LIMITED, and 403 forbidden -> FORBIDDEN.\n- Unit/integration test for getRepoSnapshot to ensure the branch -> tree SHA resolution works (mock
epos.getBranch and git.getTree).\n\nNotes: I ran
pm run lint locally (passed).
px tsc --noEmit failed here due to a local sconfig.json option (ignoreDeprecations) that caused the type-checker to error; this is unrelated to the change. If you'd like, I can also add the test skeletons and a short CI job to run them.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/octokit.ts`:
- Around line 168-170: The current fallback uses getNestedString(branch,
["commit","sha"]) which returns a commit SHA and can error when later passed to
git.getTree; update the logic that sets treeSha so that after attempting
getNestedString(branch, ["commit","commit","tree","sha"]) you do not fallback to
["commit","sha"] directly but instead, if missing, fetch the commit object and
extract its tree SHA (e.g. call octokit.git.getCommit or octokit.repos.getCommit
with the commit SHA from getNestedString(branch, ["commit","sha"]) and set
treeSha = response.data.tree.sha); keep references to treeSha, getNestedString,
branch and the octokit commit-get method to locate and implement this change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 34c090d6-37a0-4d96-9241-417dea9d6e47

📥 Commits

Reviewing files that changed from the base of the PR and between 56c5b8d and 5afa739.

📒 Files selected for processing (1)
  • src/lib/octokit.ts

Comment thread src/lib/octokit.ts Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/lib/octokit.ts
Comment on lines +151 to +155
const { data: branch } = await client.rest.repos.getBranch({
owner,
repo,
branch: repoInfo.default_branch,
});
@charles-openclaw
Copy link
Copy Markdown
Author

Follow-up pushed in 889aced to address the valid tree-SHA fallback concern.

Summary:

  • Kept the direct branch.commit.commit.tree.sha path when GitHub includes the tree SHA.
  • Removed the fallback that could pass branch.commit.sha directly to git.getTree.
  • If the branch response only has a commit SHA, the code now resolves that commit with git.getCommit and uses commit.tree.sha for git.getTree.

Verification:

  • npm run lint
  • npx tsc --noEmit
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Fallback Handling When Repository URL Is Not Found

3 participants