diff --git a/lib/index.js b/lib/index.js index 8672bb12..323f02ac 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,7 +3,7 @@ var sys = require('sys'); var net = require('net'); var NUL = '\0'; -var chars = ['R','S','K','Z','Q','C','T','D','X']; +var chars = ['R','S','K','Z','Q','C','T','D','X','E']; var charBuff = Buffer(chars.join(''),'utf8'); var UTF8 = {}; for(var i = 0; i < charBuff.length; i++){ @@ -154,6 +154,8 @@ p.parseMessage = function() { return this.parseT(); case UTF8.D: return this.parseD(); + case UTF8.E: + return this.parseE(); default: throw new Error("Unsupported message ID: " + Buffer([messageID]).toString('utf8') + " (" + messageID.toString(16) + ")"); } @@ -248,6 +250,15 @@ p.parseD = function() { return msg; }; +p.parseE = function() { + var msg = this.parseStart('Error'); + var fieldType = this.readString(1); + if(fieldType == '\0') { + return msg; + } +}; + + p.readInt32 = function() { var buffer = this.buffer; return ((buffer[this.offset++] << 24) + diff --git a/test/communication-tests.js b/test/communication-tests.js index 4405519b..43e16de1 100644 --- a/test/communication-tests.js +++ b/test/communication-tests.js @@ -36,6 +36,7 @@ test('using closed stream', function() { test('after stream connects', function() { stream.emit('connect'); + //TODO - test more of the connection packets }); }); diff --git a/test/parser-tests.js b/test/parser-tests.js index 14d268db..ac5289fb 100644 --- a/test/parser-tests.js +++ b/test/parser-tests.js @@ -192,7 +192,7 @@ test('Client', function() { format: 'text' }); }); - + }); test('parsing rows', function() { @@ -222,6 +222,12 @@ test('Client', function() { }); }); + + test('error messages', function() { + testForMessage(buffers.error(),{ + name: 'Error' + }); + }); }); diff --git a/test/test-buffers.js b/test/test-buffers.js index fae24353..c474a867 100644 --- a/test/test-buffers.js +++ b/test/test-buffers.js @@ -65,7 +65,16 @@ buffers.dataRow = function(columns) { return buf.join(true, 'D'); }; - +buffers.error = function(fields) { + fields = fields || []; + var buf = new BufferList(); + fields.forEach(function(field) { + buf.addChar(field.type); + buf.addCString(field.value); + }); + buf.add(Buffer([0]));//terminator + return buf.join(true, 'E'); +};