Skip to content

Crash when activity.type is undefined #920

Open
@tinaxd

Description

@tinaxd

Hello,

The bridge sometimes crashes with the following error:

yarn run v1.22.22
$ node ./build/src/discordas.js

/home/matrix-discord-bridge/matrix-appservice-discord/src/presencehandler.ts:122
            const type = activity.type[0] + activity.type.substring(1).toLowerCase(); // STREAMING -> Streaming;
                                      ^
TypeError: Cannot read properties of undefined (reading '0')
    at PresenceHandler.getUserPresence (/home/matrix-discord-bridge/matrix-appservice-discord/src/presencehandler.ts:122:39)
    at PresenceHandler.<anonymous> (/home/matrix-discord-bridge/matrix-appservice-discord/src/presencehandler.ts:98:29)
    at Generator.next (<anonymous>)
    at /home/matrix-discord-bridge/matrix-appservice-discord/build/src/presencehandler.js:23:71
    at new Promise (<anonymous>)
    at __awaiter (/home/matrix-discord-bridge/matrix-appservice-discord/build/src/presencehandler.js:19:12)
    at PresenceHandler.ProcessUser (/home/matrix-discord-bridge/matrix-appservice-discord/build/src/presencehandler.js:91:16)
    at PresenceHandler.<anonymous> (/home/matrix-discord-bridge/matrix-appservice-discord/src/presencehandler.ts:106:43)    at Generator.next (<anonymous>)
    at /home/matrix-discord-bridge/matrix-appservice-discord/build/src/presencehandler.js:23:71
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

When this crash occurs, the bridge crashes immediately after rebooting. However, after some time and several reboots, the crash does not reoccur.

To investigate the cause of this error, I added console.log(presence) to presencehandler.ts:120 and got the following output:

Presence {
  userID: '***',
  ~~~
  activities: [
    Activity {
      name: 'Hang Status',
      type: undefined,
      url: null,
      details: null,
      state: 'chilling',
      applicationID: null,
      timestamps: null,
      party: null,
      assets: null,
      syncID: undefined,
      flags: [ActivityFlags],
      emoji: null,
      createdTimestamp: 1720266148832
    }
  ],
  clientStatus: { desktop: 'online' }
}

It seems that this occurs when someone joins a voice channel with a Hang Status set.

I hope this helps!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions