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

TypeError: Cannot read property 'trim' of undefined #495

Open
frxstrem opened this issue Dec 26, 2016 · 7 comments
Open

TypeError: Cannot read property 'trim' of undefined #495

frxstrem opened this issue Dec 26, 2016 · 7 comments

Comments

@frxstrem
Copy link

I'm trying to use node-irc 0.5.2 to connect to an IRC server (running ircd.js 0.0.17 with default configuration). This is the code I'm using:

import irc from 'irc';

const client = new irc.Client('localhost', 'TestBot', {
  debug: true,
  channels: [ '#bottest' ],
});

However, I get this exception:

27 Dec 00:03:32 - Sending irc NICK/USER
27 Dec 00:03:32 - SEND: NICK TestBot
27 Dec 00:03:32 - SEND: USER nodebot 8 * :nodeJS IRC client
27 Dec 00:03:32 - SEND: WHOIS TestBot
27 Dec 00:03:32 - SEND: JOIN #bottest
/home/fredrik/usr/ircbot/node_modules/irc/lib/irc.js:849
                        throw err;
                        ^

TypeError: Cannot read property 'trim' of undefined
    at Client.<anonymous> (/home/fredrik/usr/ircbot/node_modules/irc/lib/irc.js:414:80)
    at emitOne (events.js:96:13)
    at Client.emit (events.js:188:7)
    at iterator (/home/fredrik/usr/ircbot/node_modules/irc/lib/irc.js:846:26)
    at Array.forEach (native)
    at Socket.handleData (/home/fredrik/usr/ircbot/node_modules/irc/lib/irc.js:841:15)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
@mousemke
Copy link

mousemke commented Jan 2, 2017

moin! i want to say, i've been using this for a while, and never had issues (built a bot on top of it). However, this is a crippling bug that has completely rendered the irc head of the bot useless. Any word on a fix (or what the issue is?). #496 does not work for me (let me know if i should open second issue)

I did some tracing of the issue.

  • on the surface it does look the same as this issue:
/Library/WebServer/Documents/_valaxypotato/node_modules/irc/lib/irc.js:849
                        throw err;
                        ^

TypeError: Cannot read property 'trim' of undefined
    at Client.<anonymous> (/Library/WebServer/Documents/_valaxypotato/node_modules/irc/lib/irc.js:372:44)
    at emitOne (events.js:101:20)

i added some logs to lib/irc and it revealed that wherever the message is coming from, the prob appears to be in parseMessage as there just isnt a 4th param

  • first i added console.log( message ) to line 110
{ prefix: server: 'irc.tinyspeck.com',
  server: 'irc.tinyspeck.com',
  command: 'rpl_namreply',
  rawCommand: '353',
  commandType: 'reply',
  args: [ 'valaxypotato', '=', '#general' ] }
  • given that rpl_namreply i checked the code. line 372 is trying to trim the undefined message.args[3]

here's my implementation, but i dont know what i would need to do on my side to fix this.

https://github.com/mousemke/_val/blob/dev/modules/core/irc.js

@mousemke
Copy link

mousemke commented Jan 2, 2017

additionally, the console.logs before that suggest maybe it's duplicating the raw response, but only with a partial arguments object

     * JOIN : #general
{ prefix: 'irc.tinyspeck.com',
  server: 'irc.tinyspeck.com',
  command: 'rpl_topic',
  rawCommand: '332',
  commandType: 'reply',
  args: [ 'valaxypotato', '#general', 'WE R POTATERS' ] }
     * rpl_topic : valaxypotato #general WE R POTATERS
{ prefix: 'irc.tinyspeck.com',
  server: 'irc.tinyspeck.com',
  command: 'rpl_namreply',
  rawCommand: '353',
  commandType: 'reply',
  args:
   [ 'valaxypotato',
     '=',
     '#general',
     'mouse nico michele wahwynn gibbo dilkrom valaxypotato turkish jfalxa stefan conor jolene mixedpoo pierre remi andybloke joderilli serendi drey sleepywolf freen eve gar1606 supermooseaoj gavin hans aki ben josh alicia fedux ninja john hydra eva joeyquixote schoonertorrent altona dadinada dax luke dezipter mell roxy xcidium schnubor subism elias mitch ola ' ] }
     * rpl_namreply : valaxypotato = #general mouse nico michele wahwynn gibbo dilkrom valaxypotato turkish jfalxa stefan conor jolene mixedpoo pierre remi andybloke joderilli serendi drey sleepywolf freen eve gar1606 supermooseaoj gavin hans aki ben josh alicia fedux ninja john hydra eva joeyquixote schoonertorrent altona dadinada dax luke dezipter mell roxy xcidium schnubor subism elias mitch ola
{ prefix: 'irc.tinyspeck.com',
  server: 'irc.tinyspeck.com',
  command: 'rpl_namreply',
  rawCommand: '353',
  commandType: 'reply',
  args: [ 'valaxypotato', '=', '#general' ] }
/Library/WebServer/Documents/_valaxypotato/node_modules/irc/lib/irc.js:850
                        throw err;
                        ^

TypeError: Cannot read property 'trim' of undefined

@mousemke
Copy link

bot still down :(

no response..... any info? need some help?

@killedWithFire9001
Copy link

use an older ver, not ideal but worked for me 🤷‍♂️ npm install [email protected]

precla added a commit to precla/irc-bot-nodejs that referenced this issue May 28, 2017
Since the >0.5.0 versions produce the following error:
martynsmith/node-irc#495
@BeauBouchard
Copy link

I still run into this issue,
In version 0.5.0 I get

TypeError: Cannot read property 'trim' of undefined
    at Client.<anonymous> (.../node_modules/irc/lib/irc.js:368:44)
    at emitOne (events.js:96:13)
    at Client.emit (events.js:188:7)
    at iterator (.../node_modules/irc/lib/irc.js:842:26)
    at Array.forEach (native)
    at TLSSocket.handleData (.../node_modules/irc/lib/irc.js:837:15)
    at emitOne (events.js:96:13)
    at TLSSocket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at TLSSocket.Readable.push (_stream_readable.js:134:10)
    at TLSWrap.onread (net.js:543:20)

I think its the same line as 0.5.2 at /node_modules/irc/lib/irc.js:372:44)
But the statement where it fails is at

case 'rpl_namreply':
                channel = self.chanData(message.args[2]);
                var users = message.args[3].trim().split(/ +/); // <-- right here line 368
                if (channel) {
                    users.forEach(function(user) {
                        var match = user.match(/^(.)(.*)$/);
                        if (match) {
                            if (match[1] in self.modeForPrefix) {

I have no working fix for this, but it seems to happen if there is a higher populated slack channel you connect the bot to through IRC

@BeauBouchard
Copy link

BeauBouchard commented Sep 28, 2017

Ok actually, i just threw an if statement around the whole thing, and it seemed to work... 😂 I would really like to see something about this, to shore it up more.

if(message.args[3]) {
                channel = self.chanData(message.args[2]);
                var users = message.args[3].trim().split(/ +/); // <-- right here line 368
                if (channel) {
                    users.forEach(function(user) {
                        var match = user.match(/^(.)(.*)$/);
                        if (match) {
                            if (match[1] in self.modeForPrefix) {
...

@BeauBouchard
Copy link

I recommend using #489 branch to test a fix for this.

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

No branches or pull requests

4 participants