Skip to content

Unespected exception on filter function #577

Description

@yhojann-cl

Have an unexpected error:

/.../node_modules/irc/lib/irc.js:849
                        throw err;
                        ^
TypeError: Cannot read properties of undefined (reading 'filter')
    at chanModes (/.../node_modules/irc/lib/irc.js:300:38)

The throw is called from:

        lines.forEach(function iterator(line) {
            if (line.length) {
                var message = parseMessage(line, self.opt.stripColors);

                try {
                    self.emit('raw', message);
                } catch (err) {
                    if (!self.conn.requestedDisconnect) {
                        throw err;
                    }
                }
            }
        });

When emit message, but in 300:38 says:

                            if (arr) {
                                channel.modeParams[mode] = channel.modeParams[mode]
                                    .filter(function(v) { return v !== param[0]; });
                            }
                            if (!arr || channel.modeParams[mode].length === 0) {
                                channel.mode = channel.mode.replace(mode, '');
                                delete channel.modeParams[mode];
                            }

When channel.modeParams[mode] is undefined. Channel has not a specific mode?, Fix it using a simple conditional:

                            if (arr && (channel.modeParams[mode] !== undefined)) {
                                channel.modeParams[mode] = channel.modeParams[mode]
                                    .filter(function(v) { return v !== param[0]; });
                            }
                            if (!arr || (channel.modeParams[mode] === undefined) || channel.modeParams[mode].length === 0) {
                                channel.mode = channel.mode.replace(mode, '');
                                delete channel.modeParams[mode];
                            }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions