-
Notifications
You must be signed in to change notification settings - Fork 10
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
Resolved issue calling method on null object #46
Resolved issue calling method on null object #46
Conversation
lib/impl/dataSources/updateCache.js
Outdated
@@ -21,7 +21,11 @@ function updateValidAndInvalidDataSources(dataSourcesToSplit, currentInvalidData | |||
logger.debug("dataSourcesToSplit", dataSourcesToSplit); | |||
currentInvalidDataSources = currentInvalidDataSources || []; | |||
var validInvalid = _.partition(dataSourcesToSplit, function(dataSourceUpdateData) { | |||
return !dataSourceUpdateData.error; | |||
if (typeof dataSourceUpdateData.error === 'function') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @davidkirwan. I have a few questions. How do we know that dataSourceUpdateData.error should always be a function? and if it is not a function, the logic is now returning true and that there is no error. If this logic is true that it is a function, it then returns !dataSourceUpdateData.error which is not invoking the function it self.
test/accept/test_dataSource.js
Outdated
@@ -720,8 +720,8 @@ module.exports.test = { | |||
forms.dataSources.updateCache(options, [dataSourceDataSingleChoice], { | |||
currentTime: new Date() | |||
}, function(err, badUpdateResult){ | |||
assert.ok(err, "Expected An Error When Updating Data Sources With Bad Data"); | |||
assert.equal(ERROR_CODES.FH_FORMS_UNEXPECTED_ERROR, err.code, "Expected A FH_FORMS_UNEXPECTED_ERROR"); | |||
//assert.ok(err, "Expected An Error When Updating Data Sources With Bad Data: " + util.inspect(err)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were these assertions commented out by accident?
Failling in the tests.
|
@camilamacedo86 @davidffrench Folks I'll add you as reviewers when I'm ready to have other eyes on the PR :) until then please ignore ! I cannot run these builds successfully locally, so having to rely on Jenkins/Travis builds to have the tests run etc for feedback. |
ah sorry @davidkirwan :-) |
@@ -21,7 +21,11 @@ function updateValidAndInvalidDataSources(dataSourcesToSplit, currentInvalidData | |||
logger.debug("dataSourcesToSplit", dataSourcesToSplit); | |||
currentInvalidDataSources = currentInvalidDataSources || []; | |||
var validInvalid = _.partition(dataSourcesToSplit, function(dataSourceUpdateData) { | |||
return !dataSourceUpdateData.error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion to fix it follows. ( do just the following code )
if ( dataSourceUpdateData ){
return !dataSourceUpdateData.error;
}
return true;
PS. In JS/Node to check if the variable is != of undefined you can just if (var)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original exceptions being raised are the following:
TypeError: Cannot read property 'error' of undefined
There seem to be situations where dataSourceUpdateData is being passed and is undefined, and calling .error on it raises an exception. So the suggested fix you make will not resolve this see the following as an example:
> var f = function(test){ test.a; }
undefined
> f(undefined);
TypeError: Cannot read property 'a' of undefined
at f (repl:1:29)
at repl:1:1
at REPLServer.defaultEval (repl.js:262:27)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer.<anonymous> (repl.js:431:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:211:10)
at REPLServer.Interface._line (readline.js:550:8)
>
Now compare to the fix I'm proposing:
> var f2 = function(test) {
... if(typeof test === 'undefined'){
..... return true;
..... }
... else{
..... return test.a;
..... }
... }
undefined
>
>
> f2({a:1});
1
> f2(undefined);
true
>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opps my bad! I'm wrong here, this does appear to work!
> var f = function(test){
... if(test){
..... return !test.a;
..... }
... return true;
... }
undefined
> f(undefined);
true
> f({a:false});
true
> f({a:true});
false
>
@camilamacedo86 @davidffrench the PR should now be in a position to be reviewed please! |
@@ -720,7 +720,7 @@ module.exports.test = { | |||
forms.dataSources.updateCache(options, [dataSourceDataSingleChoice], { | |||
currentTime: new Date() | |||
}, function(err, badUpdateResult){ | |||
assert.ok(err, "Expected An Error When Updating Data Sources With Bad Data"); | |||
assert.ok(err, "Expected An Error When Updating Data Sources With Bad Data: " + util.inspect(err)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO you should not change the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is fine, as it aided in debugging that function. By adding the contents of the err object there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the one comment from Camila, looks good to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shows fine the change ( LGTB for me ).
For we are able to merge it:
- Rebase with master
- Bump version and CHANGELOG file
@@ -720,7 +720,7 @@ module.exports.test = { | |||
forms.dataSources.updateCache(options, [dataSourceDataSingleChoice], { | |||
currentTime: new Date() | |||
}, function(err, badUpdateResult){ | |||
assert.ok(err, "Expected An Error When Updating Data Sources With Bad Data"); | |||
assert.ok(err, "Expected An Error When Updating Data Sources With Bad Data: " + util.inspect(err)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@camilamacedo86 seems since the rebase its got new changes you added in PR #45 can you take a look at the travis output perhaps you can determine why its failing based on your new changes? |
@davidkirwan all PR's before this one worked fine in the CI/Trevis. If it is not working shows that something broke in the rebase. I will give a look and let you know. |
@camilamacedo86 @davidkirwan Travis can fail sometimes, always worth restarting the build when you think the build should have passed. I have restarted it now. |
@davidkirwan Build has passed now |
Repeatable builds would be a nice feature to have eh. @davidffrench @camilamacedo86 if you are happy can you approve the PR. Thanks! |
@davidkirwan it still failing in the coverage/coveralls which means that you need to improve the tests in order to cover this scenario. |
@camilamacedo86 feel free to suggest an improvement here. |
@davidkirwan the coverage check is automatic. To check it see the following: Click on the datails for further information. For you be allowed to merge it the PR need pass in all automatic checks + the code review ( some approval ) I'd like to recommend you add a test here which covers the scenario which was fixed in the PR. PS.: I approved the PR but please wait for the @davidffrench confirmation too. |
@davidkirwan merged |
@camilamacedo86 @davidffrench @grdryn cheers folks! |
JIRA: https://issues.jboss.org/browse/RHMAP-20186
What
Getting multiples of the following exception in the fh-mbaas logs on tom1-mbaas2-ship2:
Why
fh-forms/lib/impl/dataSources/updateCache.js:24:33 contains the following:
I've not managed to figure out why yet, but it is possible for dataSourcesToSplit to be empty, or a particular element of the array to not have a error method. The fix will handle such situations.
How
The following snippet shows how the non existance of an object will no longer throw exception if checking is performed in this fashion: