ApolloError: value.toString is not a function

Some of our users are seeing the exception “ApolloError: value.toString is not a function” from a useQuery hook on one of our GraphQL queries. We haven’t been able to reproduce the error. Do you have any idea what might cause this or how we can prevent it?

We are on Apollo 3.9.10

One common feature is that so far all the affected users seem to be on Windows >= 10

Is there any stack trace attached?

I’ve looked at the AC sources and I don’t believe that this originates in our codebase - the only method call this could occur is here:

But Number.prototype.toString() is supported pretty much by every browser in history, ever: Number.prototype.toString() - JavaScript | MDN

Please note that userland code e.g. inside a custom ApolloLink that throws an error, and even browser plugins that hook into fetch and throw an error for some reason would still end up as an ApolloError, so it’s very possible that this originates outside of Apollo Client.

Do you have a full stack trace for this?

There is a second set with the same error from a different source in our app. Both go through QueryManager.js:

Unfortunately that’s only the stacktrace of ApolloError, which wraps around the original error which is thrown waaaay sooner to bring it into a predictable format.
Is there any chance you can access error.cause and look at the stack trace of that?

Scratch that, in your version error.cause probably doesn’t exist yet. You’d have to look at error.networkError, error.graphQLErrors, error.protocolErrors and error.clientErrors to find the possible original error.

We are experiencing the same problem and found that it is related to some code coming from kaspersky anti-virus.
The stack trace lead us to some function called copyHeaders() on Kaspersky side that proxies the native fetch() function.
It happens only with requests using apollo client.

Stacktrace:
"TypeError: value.toString is not a function\n at CopyHeadersValue (https://gc.kis.v2.scr.kaspersky-labs.com/FD126C42-EBFA-4E12-B309-BB3FDD723AC1/main.js?attr=fVzR6GWpTiGSWVNM_NZXCRQJPJp1YS83KyHeXrNEYHrQcGytgDBRQf_T4qtafYO_Naziog3E0EyHZxlIGcm0MLu9Fr9KBOeT6jziCBmpYyVCYk2_9sSSSNRBFLcbAlfU-1Cemzd9G8W-5q0a1FQt93BzjfgeI9I3JQLlMpPW7Af68xjJ8PD9XB4naOIJ2EXPuQ2Cq8YQIlPndkWTkJNbeQ:3742:15)\n

Yes, I discovered that this morning. There’s a conversation happening over in the Kaspersky forums. Thanks for your help Lenz and Nitzan.

We encountered something similar with a Safari extension before, and made changes on our side that should make this less likely to happen - if you can, please try to update to Release v3.11.8 · apollographql/apollo-client · GitHub

@NitzanSirota as you reported in the other thread that you are updating, please keep me posted if the update really resolves the issue. I’m still trying to reproduce the problem on my end.

I’ve opened an issue in the Apollo Client repo as well for us to track and provide communications. Feel free to follow that thread if you’re interested in updates.

I’m working on checking newer version of apollo on one of our machines, I’ll update in about 1 hour

1 Like

Sorry for not updating, we have internal problems. Trying to get to it ASAP

1 Like

hey, sorry it took so long, but we can verify newer version of apollo works :slight_smile:

2 Likes

That’s great to hear @NitzanSirota ! :slight_smile:

FYI, we have opened a new community thread where we will post updates as we have them. Thanks!

1 Like

We updated our App to 3.11.8 a while ago and have had no issues since. Thanks for your work on this.

2 Likes