Skip to content

Fix: resolve 'undefined' lobbyID in private battle creation#166

Merged
aviralsaxena16 merged 1 commit intoOpenLake:mainfrom
hansikareddy29:feature/1v1-quiz-invite-bug-fixed
Apr 9, 2026
Merged

Fix: resolve 'undefined' lobbyID in private battle creation#166
aviralsaxena16 merged 1 commit intoOpenLake:mainfrom
hansikareddy29:feature/1v1-quiz-invite-bug-fixed

Conversation

@hansikareddy29
Copy link
Copy Markdown
Contributor

@hansikareddy29 hansikareddy29 commented Apr 8, 2026

  • Fixed the invite friend url bug before it was giving undefined lobby ID now it is working fine

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling in the battle lobby creation flow with clearer error messages for users
    • Added validation to prevent navigation to invalid lobbies and display appropriate error notifications
    • Enhanced error feedback when room creation fails, guiding users to create a new battle

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 8, 2026

@hansikareddy29 is attempting to deploy a commit to the aviralsaxena16's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

🎉 Thanks for Your Contribution to CanonForces! ☺️

We'll review it as soon as possible. In the meantime, please:

  • ✅ Double-check the file changes.
  • ✅ Ensure that all commits are clean and meaningful.
  • ✅ Link the PR to its related issue (e.g., Closes #123).
  • ✅ Resolve any unaddressed review comments promptly.

💬 Need help or want faster feedback?
Join our Discord 👉 CanonForces Discord

Thanks again for contributing 🙌 – @hansikareddy29!
cc: @aviralsaxena16

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

Walkthrough

The changes enhance error handling and validation throughout the battle creation flow. The client-side StartScreen component now validates API responses before navigation, the create endpoint validates roomId generation with detailed error messages, and the lobby page adds explicit handling for invalid room IDs with improved logging.

Changes

Cohort / File(s) Summary
Battle Creation Flow
src/components/quiz/StartScreen.tsx, src/pages/api/quiz/battle/create.ts
Client validates API responses before navigating to lobby; server validates nanoid generation succeeds and returns detailed error messages in response. Both layers now check for invalid/falsy roomId values.
Lobby Validation
src/pages/quiz/lobby/[roomId].tsx
Explicitly validates roomId against the string 'undefined' on entry; logs error and sets user-facing message for invalid IDs. Dependency guard now logs readiness state instead of silently returning.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Room IDs checked with care,
Errors caught before they float,
'undefined' won't sneak through there—
Validation's safety net's afloat! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete and lacks required sections from the template. It provides only a brief informal summary without addressing the problem statement, solution explanation, testing verification, or other required documentation sections. Expand the description to include: problem explanation, solution approach, testing steps performed, and verification of fixes. Follow the template structure with sections like '🤔 Why This Change?' and '🧪 Testing'.
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 (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix: resolve 'undefined' lobbyID in private battle creation' directly summarizes the main change across all three modified files—handling undefined room/lobby IDs during private battle creation.

✏️ 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/pages/api/quiz/battle/create.ts`:
- Around line 25-27: The catch block in the room creation API (the handler in
create.ts that currently logs and returns error.message) exposes internal error
details to clients; change it to log the full error server-side (keep
console.error('[API_BATTLE_CREATE] Error creating room:', error)) but return a
generic client-safe message in the JSON response (e.g., { error: 'Failed to
create room. Please try again later.' }) and remove any use of error.message in
res.status(...).json; ensure the res call uses the same handler name/context
(the create room API handler) and preserves the 500 status.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 77d205c2-5143-4973-9245-50a16d651507

📥 Commits

Reviewing files that changed from the base of the PR and between 3c15868 and 93025c1.

📒 Files selected for processing (3)
  • src/components/quiz/StartScreen.tsx
  • src/pages/api/quiz/battle/create.ts
  • src/pages/quiz/lobby/[roomId].tsx

Comment on lines +25 to +27
} catch (error: any) {
console.error('[API_BATTLE_CREATE] Error creating room:', error.message || error);
return res.status(500).json({ error: error.message || 'Failed to create room. Please ensure Redis is configured.' });
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 | 🟠 Major

Avoid returning raw exception messages to clients.

error.message can expose backend internals (e.g., Redis connection details). Keep detailed errors in logs and return a generic client-safe message.

Suggested fix
-    } catch (error: any) {
-        console.error('[API_BATTLE_CREATE] Error creating room:', error.message || error);
-        return res.status(500).json({ error: error.message || 'Failed to create room. Please ensure Redis is configured.' });
+    } catch (error: unknown) {
+        const message = error instanceof Error ? error.message : String(error);
+        console.error('[API_BATTLE_CREATE] Error creating room:', message);
+        return res.status(500).json({ error: 'Failed to create room. Please try again.' });
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} catch (error: any) {
console.error('[API_BATTLE_CREATE] Error creating room:', error.message || error);
return res.status(500).json({ error: error.message || 'Failed to create room. Please ensure Redis is configured.' });
} catch (error: unknown) {
const message = error instanceof Error ? error.message : String(error);
console.error('[API_BATTLE_CREATE] Error creating room:', message);
return res.status(500).json({ error: 'Failed to create room. Please try again.' });
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/api/quiz/battle/create.ts` around lines 25 - 27, The catch block in
the room creation API (the handler in create.ts that currently logs and returns
error.message) exposes internal error details to clients; change it to log the
full error server-side (keep console.error('[API_BATTLE_CREATE] Error creating
room:', error)) but return a generic client-safe message in the JSON response
(e.g., { error: 'Failed to create room. Please try again later.' }) and remove
any use of error.message in res.status(...).json; ensure the res call uses the
same handler name/context (the create room API handler) and preserves the 500
status.

@aviralsaxena16 aviralsaxena16 merged commit 330b081 into OpenLake:main Apr 9, 2026
7 of 8 checks passed
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.

2 participants