EddieBot: EddieBot crashes

Description

EddieBot crash shows the error below

/root/EddieBot/dist/messageReactionAdd.js:49
    if (reaction.message.member.partial) {
                                ^

TypeError: Cannot read property 'partial' of null
    at Object.exports.messageReactionAdd (/root/EddieBot/dist/messageReactionAdd.js:49:33)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Static analysis is not perfect. As per the typescript release notes

The ! non-null assertion operator is simply removed in the emitted JavaScript code.

The transpiled code does not have this check. From dist/messageReactionAdd.js

    if (reaction.message.member.partial) {
        try {
            await reaction.message.member.fetch();
        }
        catch (error) {
            logger_1.log.error('Something went wrong when fetching the member: ', error);
            return;
        }
    }

If we wish to have this null check during runtime - we have to explicitly add that in. We can see if reaction.message.member is truthy. In TypeScript

  if (reaction.message.member && reaction.message.member!.partial) {
    try {
      await reaction.message.member!.fetch();
    } catch (error) {
      log.error('Something went wrong when fetching the member: ', error);
      return;
    }
  }

The transpiled JavaScript code

    if (reaction.message.member && reaction.message.member.partial) {
        try {
            await reaction.message.member.fetch();
        }
        catch (error) {
            logger_1.log.error('Something went wrong when fetching the member: ', error);
            return;
        }
    }

Adding this check fixes the error.

Great team work everyone 👍 - I think there are more crash issues in the log, but this is a great start 💪

This bug is caused when Eddie bot tried to add a role to a member that has left.