← Back to PRs

#11774: fix: add guards for undefined mentionRegexes arrays

by ikvyk open 2026-02-08 08:46 View on GitHub →
channel: whatsapp-web stale
Prevents `Cannot read properties of undefined (reading some)` errors when `mentionRegexes` is undefined in group chat mention detection. ## Fixes - `matchesMentionPatterns`: add `!mentionRegexes` check before `.length` - `matchesMentionWithExplicit`: extract regexes with `?? []` fallback - `isBotMentionedFromTargets`: add `?? []` fallback for `.some()` call ## Context Observed intermittent crashes in group chat sessions with error: ``` Cannot read properties of undefined (reading 'some') ``` The issue occurs when `params.mentionRegexes` is undefined during mention detection, likely due to race conditions or edge cases in config resolution. ## Changes - `src/auto-reply/reply/mentions.ts` - 2 functions fixed - `src/web/auto-reply/mentions.ts` - 1 function fixed <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR hardens group-chat mention detection against cases where `mentionRegexes` is unexpectedly `undefined`, preventing runtime crashes like `Cannot read properties of undefined (reading 'some')`. Changes are localized to mention-matching helpers used by auto-reply and the web/WhatsApp inbound path: the core mention matcher now short-circuits when no regexes are available, and callers use `?? []` when iterating regex arrays so `.some()` is always safe. <h3>Confidence Score: 4/5</h3> - This PR is likely safe to merge, but the type contract mismatch around `mentionRegexes` should be resolved to avoid future regressions. - The runtime guard additions appear correct and directly address the reported crash. The main remaining issue is that `matchesMentionPatterns` now accepts `undefined` at runtime but is still typed as `RegExp[]`, which can hide incorrect call sites and undermines type safety. - src/auto-reply/reply/mentions.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs