Skip to content

Commit

Permalink
v18.2.0 possibly created an infinite loop during error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
miql / redaphid committed Jun 8, 2017
1 parent ea241e7 commit 6eeb88a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "endo-core",
"version": "18.1.0",
"version": "18.2.0",
"description": "Put some description here",
"keywords": [],
"homepage": "https://github.com/octoblu/endo-core",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@ module.exports = ({userDeviceUuid, authorizedUuid}) ->
{uuid: userDeviceUuid}
{uuid: authorizedUuid}
]
errors: []
status:
errors:
$ref: '#/errors'
errors: []
22 changes: 16 additions & 6 deletions src/services/messages-service.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ class MessagesService
return callback newError if newError?
@_updateStatusDeviceWithError {auth, senderUuid, userDeviceUuid, error, respondTo}, callback

_updateStatusDeviceWithError: ({auth, senderUuid, userDeviceUuid, error, respondTo}, callback) =>
_updateStatusDeviceWithError: (options, callback) =>
{auth, senderUuid, userDeviceUuid, error, respondTo, alreadyTried} = options

meshblu = new MeshbluHTTP _.defaults auth, @meshbluConfig
meshblu.device userDeviceUuid, (newError, {statusDevice}={}) =>
return callback() if newError?
return callback() unless statusDevice?
update =
$set:
'status.errors':
$ref: '#/errors'
$push:
errors:
'status.errors':
$each: [
senderUuid: senderUuid
date: moment.utc().format()
Expand All @@ -63,7 +62,18 @@ class MessagesService
message: error.message
]
$slice: -99
meshblu.updateDangerously statusDevice, update, as: userDeviceUuid, callback

meshblu.updateDangerously statusDevice, update, as: userDeviceUuid, (error) =>
return callback() unless error?
return callback error if alreadyTried

if _.includes error.message, 'must be an array but is of type'
meshblu.updateDangerously statusDevice, {$set: 'status.errors': []}, (error) =>
return callback error if error?
newOptions = _.defaults {alreadyTried: true}, options
return @_updateStatusDeviceWithError newOptions, callback

return callback error

responseSchema: (callback) =>
@messageHandler.responseSchema callback
Expand Down
5 changes: 1 addition & 4 deletions test/integration/message-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,8 @@ describe 'messages', ->
.set 'Authorization', "Basic #{@credentialsDeviceAuth}"
.set 'x-meshblu-as', 'user-uuid'
.send
$set:
'status.errors':
$ref: '#/errors'
$push:
errors:
'status.errors':
$each: [
code: 500
message: 'Something very bad happened'
Expand Down
5 changes: 2 additions & 3 deletions test/integration/user-devices-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,9 @@ describe 'User Devices Spec', ->
{uuid: 'user_device_uuid'}
{uuid: 'some-uuid'}
]
errors: []
status:
errors:
$ref: '#/errors'
errors: []
.reply 201, uuid: 'status-device-uuid', token: 'status-device-token'

@updateUserStatusDevice = @meshblu
Expand Down

0 comments on commit 6eeb88a

Please sign in to comment.