mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
parsing error
This commit is contained in:
parent
f0a272a78b
commit
f9b5c7b03e
19
lib/index.js
19
lib/index.js
@ -252,10 +252,25 @@ p.parseD = function() {
|
||||
|
||||
p.parseE = function() {
|
||||
var msg = this.parseStart('Error');
|
||||
var fields = {};
|
||||
var fieldType = this.readString(1);
|
||||
if(fieldType == '\0') {
|
||||
return msg;
|
||||
while(fieldType != '\0') {
|
||||
fields[fieldType] = this.parseCString();
|
||||
fieldType = this.readString(1);
|
||||
}
|
||||
msg.severity = fields.S;
|
||||
msg.code = fields.C;
|
||||
msg.message = fields.M;
|
||||
msg.detail = fields.D;
|
||||
msg.hint = fields.H;
|
||||
msg.position = fields.P;
|
||||
msg.internalPosition = fields.p;
|
||||
msg.internalQuery = fields.q;
|
||||
msg.where = fields.W;
|
||||
msg.file = fields.F;
|
||||
msg.line = fields.L;
|
||||
msg.routine = fields.R;
|
||||
return msg;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -127,7 +127,6 @@ var testForMessage = function(buffer, expectedMessage) {
|
||||
client.on('message',function(msg) {
|
||||
lastMessage = msg;
|
||||
});
|
||||
|
||||
stream.emit('data', buffer);
|
||||
assert.same(lastMessage, expectedMessage);
|
||||
});
|
||||
@ -192,7 +191,7 @@ test('Client', function() {
|
||||
format: 'text'
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
test('parsing rows', function() {
|
||||
@ -224,9 +223,71 @@ test('Client', function() {
|
||||
});
|
||||
|
||||
test('error messages', function() {
|
||||
testForMessage(buffers.error(),{
|
||||
name: 'Error'
|
||||
test('with no fields', function() {
|
||||
var msg = testForMessage(buffers.error(),{
|
||||
name: 'Error'
|
||||
});
|
||||
});
|
||||
|
||||
test('with all the fields', function() {
|
||||
var buffer = buffers.error([{
|
||||
type: 'S',
|
||||
value: 'ERROR'
|
||||
},{
|
||||
type: 'C',
|
||||
value: 'code'
|
||||
},{
|
||||
type: 'M',
|
||||
value: 'message'
|
||||
},{
|
||||
type: 'D',
|
||||
value: 'details'
|
||||
},{
|
||||
type: 'H',
|
||||
value: 'hint'
|
||||
},{
|
||||
type: 'P',
|
||||
value: '100'
|
||||
},{
|
||||
type: 'p',
|
||||
value: '101'
|
||||
},{
|
||||
type: 'q',
|
||||
value: 'query'
|
||||
},{
|
||||
type: 'W',
|
||||
value: 'where'
|
||||
},{
|
||||
type: 'F',
|
||||
value: 'file'
|
||||
},{
|
||||
type: 'L',
|
||||
value: 'line'
|
||||
},{
|
||||
type: 'R',
|
||||
value: 'routine'
|
||||
},{
|
||||
type: 'Z', //ignored
|
||||
value: 'alsdkf'
|
||||
}]);
|
||||
|
||||
testForMessage(buffer,{
|
||||
severity: 'ERROR',
|
||||
code: 'code',
|
||||
message: 'message',
|
||||
detail: 'details',
|
||||
hint: 'hint',
|
||||
position: '100',
|
||||
internalPosition: '101',
|
||||
internalQuery: 'query',
|
||||
where: 'where',
|
||||
file: 'file',
|
||||
line: 'line',
|
||||
routine: 'routine'
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user