Skip to content

Commit

Permalink
fix(wrapProtocolError): symbols are now plain strings
Browse files Browse the repository at this point in the history
There is no need to access the `.contents` property of a symbol
when wrapping an error, as symbols are all automatically converted
to strings with the new framing refactorings
  • Loading branch information
mbroadst committed Apr 3, 2016
1 parent c544db8 commit 8d3fb8b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,12 @@ Connection.prototype._sendCloseFrame = function(condition, description) {
};

Connection.prototype._processCloseFrame = function(frame) {
this.connSM.closeReceived();
this.connSM.sendClose();
if (frame.error) {
this.emit(Connection.ErrorReceived, u.wrapProtocolError(frame.error));
}

this.connSM.closeReceived();
this.connSM.sendClose();
};

Connection.prototype._connect = function(address, sasl) {
Expand Down
2 changes: 1 addition & 1 deletion lib/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,6 @@ utilities.camelCase = function(name) {
var AMQPError = require('./types/amqp_error');
utilities.wrapProtocolError = function(err) {
if (err instanceof AMQPError)
return new errors.ProtocolError(err.condition.contents, err.description, err.errorInfo);
return new errors.ProtocolError(err.condition, err.description, err.errorInfo);
return err;
};
36 changes: 35 additions & 1 deletion test/unit/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,40 @@ describe('Client', function() {
.then(function() { return test.client.disconnect(); });
});

it('should emit errors with proper conditions (issue #230)', function(done) {
test.server.setResponseSequence([
constants.amqpVersion,
new frames.OpenFrame(test.client.policy.connect.options),
new frames.BeginFrame({
remoteChannel: 1, nextOutgoingId: 0,
incomingWindow: 2147483647, outgoingWindow: 2147483647,
handleMax: 4294967295
}),
function (prev) {
var rxAttach = frames.readFrame(prev[prev.length-1]);
return new frames.AttachFrame({
name: rxAttach.name, handle: 1,
role: constants.linkRole.sender,
source: {}, target: {},
initialDeliveryCount: 0
});
},
new frames.CloseFrame({
error: new AMQPError({ condition: ErrorCondition.ConnectionForced, description: 'test' })
})
]);

return test.client.connect(test.server.address())
.tap(function() {
test.client._connection.on('connection:errorReceived', function(err) {
expect(err.condition).to.eql('amqp:connection:forced');
expect(err.description).to.eql('test');
done();
});
})
.then(function() { return test.client.createReceiver('testing'); });
});

it('should connect and receive', function(done) {
var message = { body: { test: 'testing' } };
var messageBuf = encodeMessagePayload(message);
Expand Down Expand Up @@ -264,7 +298,7 @@ describe('Client', function() {
.then(function() { return test.client.disconnect(); });
});

it('should connect and respect the idleTimeout (issue 229)', function() {
it('should connect and respect the idleTimeout (issue #229)', function() {
var policy = new Policy({
connect: { options: { containerId: 'test', idleTimeout: 42 } },
reconnect: { retries: 0, forever: false }
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ describe('Connection', function() {
process.nextTick(function() {
expect(events).to.have.length(3);
expect(events[0]).to.eql(Connection.Connected);
expect(events[1]).to.eql(Connection.Disconnected);
expect(events[2][0]).to.eql(Connection.ErrorReceived);
expect(events[1][0]).to.eql(Connection.ErrorReceived);
expect(events[2]).to.eql(Connection.Disconnected);
done();
});
}));
Expand Down

0 comments on commit 8d3fb8b

Please sign in to comment.