kuzzleio / kuzzle-device-manager

IoT Devices & Assets Management providing digital twins, payload decoding, normalized measures, provisioning. Multi-Tenant ready for white labelled and B2B2C applications.
https://docs.kuzzle.io/official-plugins/device-manager/1
Apache License 2.0
14 stars 6 forks source link

Error during exception handling of BatchController.create() #159

Closed UncleSamSwiss closed 10 months ago

UncleSamSwiss commented 2 years ago

When I tried to handle hundreds of payloads at the same time (they were queued and then handled when the application started), I got the following error:

[TypeError: Cannot read properties of undefined (reading 'find')
       at BatchController.extractErrorByContent (/workspace/node_modules/kuzzle-device-manager/lib/core-classes/BatchProcessing/BatchController.js:38:23)
       at BatchController.create (/workspace/node_modules/kuzzle-device-manager/lib/core-classes/BatchProcessing/BatchController.js:57:32)
       at PayloadService.process (/workspace/node_modules/kuzzle-device-manager/lib/core-classes/PayloadService.js:41:13)
       at Funnel.executePluginRequest (/workspace/node_modules/kuzzle/lib/api/funnel.js:622:14)
       at FunnelProtocol.query (/workspace/node_modules/kuzzle/lib/core/shared/sdk/funnelProtocol.js:91:22)]

I don't mind BatchController.create() throwing an exception if it can't create the document for whatever reason, but I would prefer to see the actual error and not an error about error handling.

IMHO the problem is that extractErrorByContent() expects errors (coming from exception.errors) not to be undefined, but it is. Funny enough create() is the only method of BatchController that does nested error handling and honestly I have no clue why it should be different than the other methods which all have the same code pattern.

Aschen commented 2 years ago

create has this special logic because you can create a document without specifying it's ID but you still need to be able to find this document afterward.

An improved version of the BatchController will land in the JS SDK this week and then we will integrate it in the plugin instead of this custom code. It should fix the issue