martynsmith/node-irc — Issue #64: Handle errors when parsing message
Author: tapichu
Created: 2011-11-14 18:45:23+00:00
State: open

I'm getting this error sporadically with irc 0.3.2:

```
2011-11-14T07:32:37+00:00 app[app.1]: /app/node_modules/hubot/node_modules/irc/lib/irc.js:715
2011-11-14T07:32:37+00:00 app[app.1]: message.command = match[1];
2011-11-14T07:32:37+00:00 app[app.1]: ^
2011-11-14T07:32:37+00:00 app[app.1]: TypeError: Cannot read property '1' of null
2011-11-14T07:32:37+00:00 app[app.1]: at parseMessage (/app/node_modules/hubot/node_modules/irc/lib/irc.js:715:28)
2011-11-14T07:32:37+00:00 app[app.1]: at /app/node_modules/hubot/node_modules/irc/lib/irc.js:506:27
2011-11-14T07:32:37+00:00 app[app.1]: at Array.forEach (native)
2011-11-14T07:32:37+00:00 app[app.1]: at Socket. (/app/node_modules/hubot/node_modules/irc/lib/irc.js:505:15)
2011-11-14T07:32:37+00:00 app[app.1]: at Socket.emit (events.js:64:17)
2011-11-14T07:32:37+00:00 app[app.1]: at Socket._onReadable (net.js:671:31)
2011-11-14T07:32:37+00:00 app[app.1]: at IOWatcher.onReadable [as callback] (net.js:177:10)
```

And the problem is that `match` can be null under some circumstances (which I haven't pinned down yet).

``` javascript
// Parse command
match = line.match(/^([^ ]+) +/);
message.command = match[1];
```

Maybe wrapping https://github.com/martynsmith/node-irc/blob/master/lib/irc.js#L506-513 with an `if ( line.trim() != '' )` could fix it?