Closed xingped closed 9 years ago
I too am experiencing this error while using irc-message through twitch-irc.
The full trace of the error is:
[18:42:21] error - TypeError: Cannot read property 'tags' of null
at DestroyableTransform._transform (/Users/hoon/Workspace/ppr/node_modules/twitch-irc/node_modules/irc-message/index.js:148:35)
at DestroyableTransform.Transform._read (/Users/hoon/Workspace/ppr/node_modules/twitch-irc/node_modules/irc-message/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
at DestroyableTransform.Transform._write (/Users/hoon/Workspace/ppr/node_modules/twitch-irc/node_modules/irc-message/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12)
at doWrite (/Users/hoon/Workspace/ppr/node_modules/twitch-irc/node_modules/irc-message/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:237:10)
at writeOrBuffer (/Users/hoon/Workspace/ppr/node_modules/twitch-irc/node_modules/irc-message/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:227:5)
at DestroyableTransform.Writable.write (/Users/hoon/Workspace/ppr/node_modules/twitch-irc/node_modules/irc-message/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:194:11)
at Socket.ondata (_stream_readable.js:540:20)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)
Same, happens during a client reload or close.
Here's a temporary hack I made on ./index.js
:
var stream = through.obj(function(chunk, encoding, done) {
buffer += chunk.toString()
messages = buffer.split(/\r\n/)
buffer = messages.pop()
// TEMP FIX FOR CRASHING
// by Jacob on August 6th, 2015
for (var i = 0; i < messages.length; i++) {
var message = messages[i]
var parsed = parse(message)
// support for IRCv3.2 server-time spec
var timestamp = parsed ? parsed.tags.time : null;
if (parsed && convertTimestamps) {
var converted = iso8601.toDate(timestamp)
parsed.tags.time = (converted) ? converted : new Date(NaN)
}
if (parsed && shouldParsePrefix) {
parsed.prefix = parsePrefix(parsed.prefix)
}
if (parsed === null) {
// Ignore Message If Parsed is Invalid
// Don't Emit Error, due to Crash
// this.emit('error', new Error('Invalid IRC message'))
} else {
this.push(parsed)
}
}
done()
})
Could you please send in a pull request and add tests? Thank you!
On Fri, Aug 7, 2015 at 12:15 AM Jacob Payne notifications@github.com wrote:
Here's a temporary hack I made on ./index.js:
var stream = through.obj(function(chunk, encoding, done) {
buffer += chunk.toString() messages = buffer.split(/\r\n/) buffer = messages.pop() // TEMP FIX FOR CRASHING // by Jacob on August 6th, 2015 for (var i = 0; i < messages.length; i++) { var message = messages[i] var parsed = parse(message) // support for IRCv3.2 server-time spec var timestamp = parsed ? parsed.tags.time : null; if (parsed && convertTimestamps) { var converted = iso8601.toDate(timestamp) parsed.tags.time = (converted) ? converted : new Date(NaN) } if (parsed && shouldParsePrefix) { parsed.prefix = parsePrefix(parsed.prefix) } if (parsed === null) { // Ignore Message If Parsed is Invalid // Don't Emit Error, due to Crash // this.emit('error', new Error('Invalid IRC message')) } else { this.push(parsed) } } done() })
— Reply to this email directly or view it on GitHub https://github.com/SIGKELL/irc-message/issues/18#issuecomment-128536789.
Is the code an appropriate permanent fix though? He did mention it was a temporary hack. On Aug 7, 2015 11:46 AM, "Fionn Kelleher" notifications@github.com wrote:
Could you please send in a pull request and add tests? Thank you!
On Fri, Aug 7, 2015 at 12:15 AM Jacob Payne notifications@github.com wrote:
Here's a temporary hack I made on ./index.js:
var stream = through.obj(function(chunk, encoding, done) {
buffer += chunk.toString() messages = buffer.split(/\r\n/) buffer = messages.pop()
// TEMP FIX FOR CRASHING // by Jacob on August 6th, 2015
for (var i = 0; i < messages.length; i++) { var message = messages[i] var parsed = parse(message)
// support for IRCv3.2 server-time spec var timestamp = parsed ? parsed.tags.time : null;
if (parsed && convertTimestamps) { var converted = iso8601.toDate(timestamp) parsed.tags.time = (converted) ? converted : new Date(NaN) } if (parsed && shouldParsePrefix) { parsed.prefix = parsePrefix(parsed.prefix) } if (parsed === null) { // Ignore Message If Parsed is Invalid // Don't Emit Error, due to Crash
// this.emit('error', new Error('Invalid IRC message')) } else { this.push(parsed) }
}
done() })
— Reply to this email directly or view it on GitHub <https://github.com/SIGKELL/irc-message/issues/18#issuecomment-128536789 .
— Reply to this email directly or view it on GitHub https://github.com/SIGKELL/irc-message/issues/18#issuecomment-128793116.
Seems to be an error with logging into npm at the moment, I'll try publish it later.
% npm publish
+ irc-message@3.0.2
Unfortunately I can't seem to reproduce what caused this error as your library is being used in another library I'm using (twitch-irc), but I just thought I'd share. Maybe throw in some error/sanity checking.