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

onExit can return an undefined error #207

Closed
ekilah opened this issue Aug 12, 2021 · 6 comments · May be fixed by #212
Closed

onExit can return an undefined error #207

ekilah opened this issue Aug 12, 2021 · 6 comments · May be fixed by #212

Comments

@ekilah
Copy link

ekilah commented Aug 12, 2021

The typings suggest that the error can be null | PlaidLinkError in the onExit callback. I've got bug reports from my production environment that suggest that error is occasionally/rarely undefined instead of null.

export type PlaidLinkOnExit = (
  error: null | PlaidLinkError,
  metadata: PlaidLinkOnExitMetadata
) => void;

Here's an example stack trace where we had a crash after we were filtering out error !== null explicitly:

TypeError Cannot read property 'error_type' of undefined 
    .../src/components/.../index.tsx:88:31 P.onExit
    .../src/components/.../index.tsx:145:15 Object.onExit
    https://cdn.plaid.com/link/v2/stable/link-initialize.js:1:66061 Object.exit
    https://cdn.plaid.com/link/v2/stable/link-initialize.js:1:47225 

Obviously a check for if (error) will work fine, so I expect many developers wouldn't even notice.

Assuming that this is actually an expected situation, it suggests there are deeper issues with the typings in the library. An obvious but probably incomplete fix is to change the types.ts file to also include undefined, so I wanted to make an issue first to see if anyone could figure out the rest.

@skylarmb
Copy link
Contributor

hi @ekilah I really appreciate this very keen eye here.

Just from personal experience with Typescript, I would highly recommend never distinguishing between undefined and null in your code. For example at Plaid we always perform checks in the form of error != null, instead of error !== null. This is hard to enforce in a linter, but in my opinion, a good style guide should encourage this.

That said I am going to file a ticket internally for this. I suspect we would much rather just fix this clearly undesirable behavior of the SDK than add undefined as a possible error value here.

Does the metadata from the onExit give any hints as to what is happening? Do you have any request ids or session ids?

@ekilah
Copy link
Author

ekilah commented Aug 30, 2021

A screenshot of what we log to our error reporting service from one of the occurrences we had of this, before I fixed it, shows that the metadata was also null or undefined (unfortunately the nature of JSON.stringify is that the bug reporting service here merges both null and undefined to "null" which made figuring this out more difficult, funny enough):

image

We don't currently log the Plaid request IDs, and I've since fixed the error on our end, so I probably won't be able to produce those for you unfortunately.

That said I am going to file a ticket internally for this. I suspect we would much rather just fix this clearly undesirable behavior of the SDK than add undefined as a possible error value here.

Your call, though until/unless this is resolved, others might hit this issue, and adding | undefined is pretty cheap and easy to remove again later, so if it were my decision, I'd lean towards correcting the typing in the mean time. Depends on your release cycles and how long until this might be fixed too.

Anyway, thanks for the reply! Sorry I can't provide those IDs for you. If I can do anything else to help, let me know!


Re: TS thoughts (more of a for-fun response, not super important to the topic at hand)

I agree in general that a language having two nullish types like JS does is tricky, and is best navigated with caution. That's especially true when writing code against third-party libraries. However, using TypeScript is a great way to avoid errors with mishandling them, as long as typings are correctly describing the possibilities. If the typings from Plaid were correctly including | undefined, and we were using !== null, we would have gotten a compiler error telling us that we weren't handling undefined properly.

That's why I made the issue here - I disagree that != checks are better than !== checks at a high level (though obviously it'd be great for avoiding bugs like this one), but that's a bit more of a tabs-vs-spaces flame war that we can leave to other discussion boards 😛

@skylarmb
Copy link
Contributor

note to self: wonder if this is related to #204 👀

@skylarmb
Copy link
Contributor

skylarmb commented Aug 31, 2021

hey @ekilah I chatted with the team yesterday. We definitely want to fix this and always return just null, but because we are more focused on some migrations we are doing in the longer term that will result in this more ideal behavior anyways, its unlikely we will fix this behavior in our soon-to-be-deprecated code, so i'll add the type you suggested in the meantime.

Thanks for the issue report!

@skylarmb
Copy link
Contributor

skylarmb commented Apr 4, 2022

@ekilah can you tell me if you have seen any instances of this in the last ~2 weeks in production environment? we finally rolled out the architectural change I was talking about above which should resolve the undefined vs null values in callbacks. They should always be null now afaik.

@ekilah
Copy link
Author

ekilah commented Apr 5, 2022

Hi @skylarmb - unfortunately, I can't tell you one way or another, since I fixed/prevented this on our side when I reported this. But, glad to hear it's fixed upstream! 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants