Skip to content

fix: guard empty documents list before accessing .first (fixes #778)#779

Open
dolliecoder wants to merge 2 commits intoAOSSIE-Org:masterfrom
dolliecoder:fix/guard-empty-documents
Open

fix: guard empty documents list before accessing .first (fixes #778)#779
dolliecoder wants to merge 2 commits intoAOSSIE-Org:masterfrom
dolliecoder:fix/guard-empty-documents

Conversation

@dolliecoder
Copy link
Copy Markdown

@dolliecoder dolliecoder commented Mar 2, 2026

Description

Fixes #778

Adds a defensive guard in removeUserFromSubscriberList to prevent a
StateError when accessing response.documents.first if the list is empty.

Previously, calling .first on an empty list could cause a runtime crash.
The method now safely returns early when no matching subscription document exists.


Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings

@dolliecoder dolliecoder requested a review from M4dhav as a code owner March 2, 2026 11:12
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 2, 2026

🎉 Welcome @dolliecoder!
Thank you for your pull request! Our team will review it soon. 🔍

  • Please ensure your PR follows the contribution guidelines. ✅
  • All automated tests should pass before merging. 🔄
  • If this PR fixes an issue, link it in the description. 🔗

We appreciate your contribution! 🚀

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 2, 2026

Warning

Rate limit exceeded

@dolliecoder has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 12 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between dd8aba8 and db513f5.

📒 Files selected for processing (1)
  • lib/controllers/upcomming_rooms_controller.dart
📝 Walkthrough

Walkthrough

The removeUserFromSubscriberList method in the upcoming rooms controller has been refactored to fetch matching subscriber documents and verify their existence before deletion. Additionally, a field name correction from userID to userId was applied for consistency.

Changes

Cohort / File(s) Summary
Subscriber Removal Logic
lib/controllers/upcomming_rooms_controller.dart
Enhanced removeUserFromSubscriberList method with document fetching and existence validation. Corrected query field from userID to userId and added early return guard to prevent errors when no matching subscription exists.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A fix so fine, a guard so neat,
Query fields aligned, the dance complete,
No empty deletions shall pass our way,
The subscriber list is safe to slay! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: guarding against empty documents before accessing .first, which aligns with the code changes that add early return logic and correct the query field.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 `@lib/controllers/upcomming_rooms_controller.dart`:
- Around line 113-124: The unsubscribe query uses the wrong field name
("userId") causing no matches; change the Query.equal call in the unsubscribe
logic to use "userID" (the same field used elsewhere when writing/reading
subscriptions) so the query that builds response (the block that constructs
Query.equal('userId', authStateController.uid), Query.equal('upcomingRoomId',
upcomingRoomId)) becomes Query.equal('userID', authStateController.uid),
ensuring the response.documents lookup and subsequent subscribeDocument handling
find the correct document.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf1dbe2 and dd8aba8.

📒 Files selected for processing (1)
  • lib/controllers/upcomming_rooms_controller.dart

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.

Potential StateError when accessing .first on empty documents list in removeUserFromSubscriberList

1 participant