Refactor: improve idle user checks and error handling in Discord actions#2568
Refactor: improve idle user checks and error handling in Discord actions#2568prakashchoudhary07 merged 4 commits intodevelopfrom
Conversation
WalkthroughAdds defensive guards and identity validation to Discord idle-user processing: introduces a Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
models/discordactions.js (1)
667-708:⚠️ Potential issue | 🟠 Major
updateIdle7dUsersOnDiscordhas the same vulnerabilities that were just fixed inupdateIdleUsersOnDiscord.The refactored guards (optional chaining on
roles,discordIdextraction,discordMemberIdsset, null-safeuserDataaccess, graceful error handling) were not applied here. Specific issues:
- Line 668-670:
discordUser.roles.includes(...)— no optional chaining; crashes ifrolesis undefined.- Line 692:
userData.data().roles.archived— accessed before the.existscheck on line 693; throws ifdata()returnsnull.- Line 707:
throw new Error(...)insidePromise.allmap — one user failure aborts processing of all remaining users.Apply the same defensive pattern used in
updateIdleUsersOnDiscord.
🤖 Fix all issues with AI agents
In `@models/discordactions.js`:
- Around line 417-436: The module-level array allMavens is leaking state across
invocations; move its declaration into the function(s) that use it (e.g., inside
updateIdleUsersOnDiscord and updateIdle7dUsersOnDiscord) or explicitly reset it
at the start of those functions before any .push() calls so each run starts with
an empty list; update any usage sites (including the
!allMavens.includes(discordId) check and where allMavens is passed/returned) to
use the locally-scoped variable or newly-passed parameter to avoid stale
entries.
In `@test/unit/models/discordactions.test.js`:
- Around line 1082-1089: The test title for the case exercising
updateIdleUsersOnDiscord is out of sync with its expectations; either change the
string describing the test or update the asserts. Update the it(...) description
to reflect the asserted values (expect res.totalIdleUsers === 1,
res.totalUserRoleToBeAdded === 1, res.totalUserRoleToBeRemoved === 1,
res.totalArchivedUsers === 0) so the test name matches the assertions,
referencing the test block that calls updateIdleUsersOnDiscord and inspects
res.totalIdleUsers, res.totalUserRoleToBeAdded, res.totalUserRoleToBeRemoved,
and res.totalArchivedUsers.
|
test will be handle here |
| it("should return totalIdleUsers as 1,totalArchivedUsers as 0, totalRoleToBeAdded as 1", async function () { | ||
| const dev = "true"; | ||
| const res = await updateIdleUsersOnDiscord(dev); | ||
| expect(res.totalIdleUsers).to.be.equal(2); | ||
| expect(res.totalUserRoleToBeAdded).to.be.equal(2); | ||
| expect(res.totalIdleUsers).to.be.equal(1); | ||
| expect(res.totalUserRoleToBeAdded).to.be.equal(1); | ||
| expect(res.totalUserRoleToBeRemoved).to.be.equal(1); | ||
| expect(res.totalArchivedUsers).to.be.equal(1); | ||
| expect(res.totalArchivedUsers).to.be.equal(0); |
There was a problem hiding this comment.
Handle this also, please, in the test PR.
Please make sure that we do not change the tests, until there a actual functionality change
Date: 10-2-2026
Developer Name: @vinit717
Description
Streamline check for idle user tagging
Documentation Updated?
Under Feature Flag
Database Changes
Breaking Changes
Development Tested?
Screenshots
Screenshot 1
Test Coverage
Screenshot 1
Additional Notes