Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/app/api/generate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,24 @@ export async function POST(req: Request) {
{ status: 400 },
);
}

const [repoInfo, repoContents] = await Promise.all([
let repoInfo, repoContents;
[repoInfo, repoContents] = await Promise.all([
getRepoData(owner, repo),
getRepoContents(owner, repo),
]);

// If the Octokit helpers swallow errors and return null/empty results,
// handle that case explicitly here instead of relying on try/catch.
if (!repoInfo) {
return NextResponse.json(
{
error:
"Unable to fetch repository from GitHub. Please verify the repository exists, is public, and the URL is correct.",
},
{ status: 400 },
);
}
Comment on lines +59 to +75
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | πŸ”΄ Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find octokit.ts
find . -name "octokit.ts" -o -name "*octokit*" | head -20

Repository: BeyteFlow/ReadmeGenAI

Length of output: 85


🏁 Script executed:

#!/bin/bash
# Check src/lib directory structure
ls -la src/lib/ 2>/dev/null | head -20

Repository: BeyteFlow/ReadmeGenAI

Length of output: 294


🏁 Script executed:

#!/bin/bash
# Search for getRepoData and getRepoContents definitions
rg -n "async.*getRepoData|function getRepoData" -A 20 --type ts

Repository: BeyteFlow/ReadmeGenAI

Length of output: 1100


🏁 Script executed:

#!/bin/bash
# Search for getRepoContents definition
rg -n "async.*getRepoContents|function getRepoContents" -A 20 --type ts

Repository: BeyteFlow/ReadmeGenAI

Length of output: 1015


Critical: This try/catch is dead code β€” getRepoData and getRepoContents never throw.

Looking at src/lib/octokit.ts, both functions have internal try/catch blocks that swallow errors:

  • getRepoData (lines 20–35) catches all errors and returns null
  • getRepoContents (lines 40–58) catches all errors and returns []

Since both promises always resolve successfully, Promise.all will never reject, so the catch block (including the 404 and 403 handling) will never execute.

To make this work, either:

  1. Remove the try/catch blocks in octokit.ts so errors propagate to the caller here, OR
  2. Modify the octokit helpers to return an error-aware result object (e.g., { data: null, error: {...} }) that preserves the status code, OR
  3. Check the null/[] return values here instead of trying to catch exceptions (though this loses the status code differentiation)

Option 1 is the simplest approach aligned with the PR's goal. After that change, update the type handling for repoInfo and repoContents downstream (lines 92–119) to account for the actual response types.

πŸ€– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/api/generate/route.ts` around lines 59 - 89, The try/catch in
route.ts is dead because getRepoData and getRepoContents swallow errors and
never reject; change octokit helpers instead: remove the internal try/catch in
getRepoData and getRepoContents so they throw on error (propagating status and
message), then adjust callers in route.ts (variables repoInfo, repoContents and
the downstream logic that consumes them) to handle possibly undefined/null
responses and the thrown errors via the existing try/catch block so the 404/403
NextResponse branches work as intended.


const files = Array.isArray(repoContents)
? repoContents.map((f: { name: string }) => f.name)
: [];
Expand Down Expand Up @@ -154,7 +166,7 @@ export async function POST(req: Request) {
console.error("README Generation Failed:", message);

return NextResponse.json(
{ error: "Failed to generate README. Check your URL and try again." },
{ error: "AI generation failed. Please try again in a moment." },
{ status: 500 },
);
}
Expand Down