feedhenry / fh-js-sdk

FeedHenry Javascript SDK
http://feedhenry.org/fh-js-sdk/
Apache License 2.0
8 stars 37 forks source link

Client gets null pointer exception when connection tag is disabled #256

Open MikeyBurkman opened 6 years ago

MikeyBurkman commented 6 years ago

This is related to this PR: https://github.com/feedhenry/fh-js-sdk/pull/213

When the connection tag is disabled, all the parameters passed to the error callback, including req, are apparently undefined. That PR assumes that req is defined, even though there's an explicit check for req not being there a couple lines above it. Line 86 in initializer.js thus throws a null pointer instead of calling the callback with the appropriate error.

https://github.com/feedhenry/fh-js-sdk/blob/2.23.0/src/modules/initializer.js#L86

jcesarmobile commented 6 years ago

By the time that PR was made, when the connection tag was disabled it returned a valid req with 400 code, it might have changed now. If it has changed, it might affect the native SDKs as they also check for the 400 error code.

cc @danielpassos

MikeyBurkman commented 6 years ago

The weird part is why the error callback is getting no arguments (from what my client is seeing). I'm not sure if that's correct/expected behavior or not.

Regardless, if there's a check for req being null in one part of the function, then presumably that means the function should handle req being null throughout the entire function, so this code will still need changing, either to remove the null check once we have fixed it so req can never be null, or to add the null check anywhere we look for properties on req.

image image 1

camilamacedo86 commented 6 years ago

IMHO if we have a scenario where the req can be null and cause the "null pointer exception” we should validate it (savedHost && req && req.status !== 400) { regardless of whether we have to check other points as well.

c/c @jcesarmobile

jcesarmobile commented 6 years ago

We should know first if the null req is because it's disabled or because of another reason. If it's because of another reason, we should use the savedHost when req is null, so they can still connect with the saved host.

So, if req null because of another reason it should be

(savedHost && (!req || req.status !== 400)) //still use the savedHost if req is null or it's not a 400 error

If req is null because it's disabled, then all the code could be simplified as we don't have to check for the 400 error anymore

camilamacedo86 commented 6 years ago

@jcesarmobile make sense 👍

camilamacedo86 commented 6 years ago

@jcesarmobile could you made a PR for this fix, please?

jcesarmobile commented 6 years ago

I can make it, but I have no way of testing if it works fine as I no longer have access to any studio

camilamacedo86 commented 6 years ago

@jcesarmobile the JIRA for it is: https://issues.jboss.org/browse/RHMAP-19268 Since you did the change before, could you do the fix and add the link into the JIRA, also add the steps required to test it.

MikeyBurkman commented 6 years ago

I still haven't heard anyone state why just adding a null check here is actually the correct solution. As my debugging screenshot shows, all args passed to the error handler are undefined in this case. Surely that's not expected behavior?

jcesarmobile commented 6 years ago

@camilamacedo86 I no longer work at Red Hat, so I have no access to any RHMAP studio instance to test if disabled connections are returning a null req now instead of returning a req with a error code 400. I don't have access to RHMAP JIRA neither.

camilamacedo86 commented 6 years ago

@jcesarmobile sorry. I didn't realize that. Tks for all your support here.

MikeyBurkman commented 6 years ago

@camilamacedo86 I just spoke with the client dev about reproducing it, and it looks like the null pointer is only thrown when running the app on our local browser. When run on an iPhone, disabling the connection tag acts like it should. I don't have a clue why, but the app/init call results in the error handler getting called with all null args in desktop Chrome. So probably not something we should be terribly concerned with.

Anyways, while it will work against a production build, testing it locally is still a bit of an issue for us. We think it's a CORS issue trying to do the app/init call on app startup. Do you have any recommendations for doing this from Chrome or Safari on the desktop?

(Also, adding those null checks in the handler are still probably a good idea 👍 )

evanshortiss commented 6 years ago

@MikeyBurkman @camilamacedo86 might be worth looking into why the JSONP fallback (shouldd be used in browser) is not returning a response consistent with the endpoint the mobile device hits. Sounds like that might be the root cause?

camilamacedo86 commented 6 years ago

@MikeyBurkman shows that the scenario where the req can be null/undefined is exactly my guess shared with you in the slack when you raised it. The client app is running in a local environment and it is not setup/configurated to do the request for the cloud app deployed in RHMAP. The solution is to configure the local environment to call the cloud application deployed into RHMAP or use a new version of SDK when the PR https://github.com/feedhenry/fh-js-sdk/pull/257 be merged.

IHMO the root cause anyway is the code implementation is not covering this scenario which will be solved with the PR https://github.com/feedhenry/fh-js-sdk/pull/257.

c/c @davidffrench let's do the merge? Could you check it?

MikeyBurkman commented 6 years ago

We always knew the req was null from the beginning. The screenshot demonstrates that clearly. We just didn't know why it was null. And to be honest, we still don't.

davidffrench commented 6 years ago

I agree with @MikeyBurkman , the null checks in the handler are required no matter what, so the PR should be merged. @evanshortiss I reckon you are correct, it must be an issue or inconsistency with the JSONP fallback.

camilamacedo86 commented 6 years ago

@davidffrench

According to [~mburkman] this issue just occurs when the client application is running locally and [~evanshortiss] believe that it can have some relation to and you agreed either that it must be an issue or inconsistency with the JSONP fallback. My guess is that the client app is not set up to use the cloud app deployed on RHMAP.

So, could we close this issue as the PR is merged or is required here some further action?