Azure and the “Cannot read property ‘isSuccessful’ of null” error

Working on a nodejs project for azure the following error appeared when using queues:

C:\workspaces\demo\node_modules\azure\lib\services\queue\queueservice.js:582
callback(returnObject.error, returnObject.response.isSuccessful, returnO
^
TypeError: Cannot read property 'isSuccessful' of null
at QueueService.deleteMessage.finalCallback (C:\workspaces\demo\node_modules\azure\lib\services\queue\queueservice.js:582:57)
at ServiceClient._initDefaultFilter.filter (C:\workspaces\demo\node_modules\azure\lib\services\core\serviceclient.js:602:11)
at QueueService.deleteMessage.processResponseCallback (C:\workspaces\demo\node_modules\azure\lib\services\queue\queueservice.js:585:5)
at Request.ServiceClient._performRequest.self._buildRequestOptions.processResponseCallback [as _callback] (C:\workspaces\demo\node_modules\azure\lib\services\core\serviceclient.js:239:11)
at Request.init.self.callback (C:\workspaces\demo\node_modules\azure\node_modules\request\index.js:148:22)
at Request.EventEmitter.emit (events.js:88:17)
at ClientRequest.Request.init.self.clientErrorHandler (C:\workspaces\demo\node_modules\azure\node_modules\request\index.js:257:10)
at ClientRequest.EventEmitter.emit (events.js:88:17)
at CleartextStream.socketCloseListener (http.js:1304:9)
at CleartextStream.EventEmitter.emit (events.js:115:20)

That happened because in the queueservice.js file the deleteMessage function was defined as follows:

QueueService.prototype.deleteMessage = function (queue, messageid, popreceipt, optionsOrCallback, callback) {
var options;
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });

validate.validateArgs('deleteMessage', function (v) {
v.string(queue, 'queue');
v.queueNameIsValid(queue);
v.callback(callback);
});

if (!popreceipt) {
throw new Error('A message retrieved using \'peekMessages\' can not be deleted! Use \'getMessages\' instead.');
}

var webResource = WebResource.del(queue + '/messages/' + messageid)
.withQueryOption(QueryStringConstants.POP_RECEIPT, popreceipt, null, true);

var processResponseCallback = function (responseObject, next) {
var finalCallback = function (returnObject) {
callback(returnObject.error, returnObject.response.isSuccessful, returnObject.response);
};

next(responseObject, finalCallback);
};

this.performRequest(webResource, null, options, processResponseCallback);
};

If you look at the code, you will see a part that reads callback(returnObject.error, returnObject.response.isSuccessful, returnObject.response);.
We’ll this part was causing an error because returnObject.response was null.
The problem with this is that azure (at least the nodejs SDK) uses returnObject.response as null when an error was captured when processing a request… so the same guys use returnObject.response as null and then try to read it -_-

My solution was to check the returnObject before:

var isSuccessful = (returnObject.response == null)?false:returnObject.response.isSuccessful;
callback(returnObject.error, isSuccessful, returnObject.response);

Maybe is not the best solution, but at least now this is working!

  1. No comments yet.

  1. No trackbacks yet.

WP-SpamFree by Pole Position Marketing