Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add undef protection to categorize #21

Merged
merged 2 commits into from
May 11, 2021

Conversation

joemcmahon
Copy link
Collaborator

In some cases, messages arrive with message.text set to undefined. This
causes the iSMention check in categorize.js to fail and causes
CoreBot.js to throw a "An error occurred in the categorize middleware:
TypeError: Cannot read property 'indexOf' of undefined" error.

Add a check for the message text being undefined so we skip the mention
and direct_mention checks (they can't pass anyway if the message is
undefined).

middleware/categorize.js Outdated Show resolved Hide resolved
@joemcmahon
Copy link
Collaborator Author

joemcmahon commented May 10, 2021 via email

@joemcmahon joemcmahon force-pushed the fix-ismention-potential-exception branch from 3f6de4e to f0a115f Compare May 11, 2021 02:32
@joemcmahon
Copy link
Collaborator Author

Simplified version: I set message.text to "", which causes the following checks to fail, appropriately, but doesn't cause them to throw an exception.

In some cases, messages arrive with message.text set to undefined. This
causes the iSMention check in categorize.js to fail and causes
CoreBot.js to throw a "An error occurred in the categorize middleware:
TypeError: Cannot read property 'indexOf' of undefined" error.

Set the text to "" to allow the checks to occur (and fail) but not
throw an exception.
@joemcmahon joemcmahon force-pushed the fix-ismention-potential-exception branch from f0a115f to c35bdc9 Compare May 11, 2021 02:35
@joemcmahon
Copy link
Collaborator Author

Aaaand of course I reversed the sense of the if check. Fixed.

@brh55 brh55 merged commit fec0083 into brh55:master May 11, 2021
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