Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fiqare secmotic rules #411

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions lib/bindings/HTTPBindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var http = require('http'),
},
transport = 'HTTP';

function handleError(error, req, res, next) {
function handleError(error, req, res) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the fix for this is removing next from the signature of the function of this change is actually raising another kind of bug in the function: it should call next() upon completion but it is not doing it.

A similar case would be the one with returnCommands() modification, some lines below.

@AlvaroVega what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess express is expecting always a function with req, res, next) args

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been discussing this case with @AlvaroVega and the solution here shouldn't be to remove "next" for the parametrs, but adding the next(); call to the end of the function, i.e. just after L59.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in a2e11f6

var code = 500;

config.getLogger().debug(context, 'Error [%s] handing request: %s', error.name, error.message);
Expand Down Expand Up @@ -135,7 +135,7 @@ function checkMandatoryParams(queryPayload) {
* This middleware checks whether there is any polling command pending to be sent to the device. If there is some,
* add the command information to the return payload. Otherwise it returns an empty payload.
*/
function returnCommands(req, res, next) {
function returnCommands(req, res) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly to handleError() the solution should be to call next(); in the proper place (I guess that just after L205, but not fully sure).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in a2e11f6

function updateCommandStatus(device, commandList) {
var updates, cleanCommands;

Expand All @@ -159,7 +159,7 @@ function returnCommands(req, res, next) {
updates = commandList.map(createCommandUpdate);
cleanCommands = commandList.map(cleanCommand);

async.parallel(updates.concat(cleanCommands), function(error, results) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

results seems a reminder of a log that was necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case the fix should be to use results to provide a proper log messages based on it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we continue to rely on ISO 25010 to improve software quality. Mainly:

Rule 1: Unused function parameters should be removed, based on:

MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
MISRA C:2012, 2.7 - There should be no unused parameters in functions
CERT, MSC12-C. - Detect and remove code that has no effect or is never executed

So, this is fixed in a2e11f6

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We agree that unused parameters should be avoided. However, we are proposing a different solution for this case: instead of removing the unused results parameter, let's add a log trace that uses results to print some useful information in the logs for the user.

What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the maintainability axis of ISO 25010, I think it is counterproductive to add code to the function to use a variable that is currently deprecated, which makes it less readable. Therefore, before adding code that will not be functional, I prefer to leave the function as it was, with the variable "results".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 9dfbdcb

async.parallel(updates.concat(cleanCommands), function(error) {
if (error) {
// prettier-ignore
config.getLogger().error(
Expand Down
2 changes: 1 addition & 1 deletion lib/bindings/MQTTBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function start(callback) {
}
});
mqttClient.on('message', commonBindings.mqttMessageHandler);
mqttClient.on('connect', function(ack) {
mqttClient.on('connect', function() {
config.getLogger().info(context, 'MQTT Client connected');
recreateSubscriptions();
});
Expand Down
2 changes: 1 addition & 1 deletion lib/commonBindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function manageConfigurationRequest(apiKey, deviceId, device, objMessage) {
* @param {Number} index Index of the group in the array.
* @return {Array} Updated array of functions.
*/
function processMeasureGroup(device, apikey, previous, current, index) {
function processMeasureGroup(device, apikey, previous, current) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaDoc entry for index (L115) should be removed also.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 662a458

var values = [];

if (current.command) {
Expand Down
2 changes: 2 additions & 0 deletions lib/iotaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ function mergeDeviceWithConfiguration(deviceData, configuration, callback) {
deviceData[fields[i]] = configuration[confField];
} else if (!deviceData[fields[i]] && (!configuration || !configuration[confField])) {
deviceData[fields[i]] = defaults[i];
} else {
config.getLogger().debug(context, 'at field %d configuration merging logic did not merge anything', i);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "%d" the right formatter for integer in JavaScript?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing log from error to debug level, sure?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably you are seeing a partical commit... if you clear filters in diff tab the actual change shown is the addition of the a debug line. I mean, there wasn't any error() logging here before.

Copy link
Member

@AlvaroVega AlvaroVega Jan 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed "%d" is correct. Thus NTC (I guess)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in a2e11f6

}

if (deviceData[fields[i]] && ['active', 'lazy', 'commands'].indexOf(fields[i]) >= 0) {
Expand Down