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

Cannot read property 'toLowerCase' of null #219

Closed
lldata opened this issue Jun 7, 2018 · 24 comments
Closed

Cannot read property 'toLowerCase' of null #219

lldata opened this issue Jun 7, 2018 · 24 comments
Labels

Comments

@lldata
Copy link

lldata commented Jun 7, 2018

  • VSCode Version: 1.22.2
  • OS Version: win7
  • REST Client Version: 0.18.4

image

After running VS Code REST client for a while, I get this error when trying to call any REST service.
"Cannot read property 'toLowerCase' of null".

I can't reproduce it. It just happens every couple of hours or days.
Closing the http file does not resolve it. Only restarting VSCode resolves the issue.

It is quite annoying. I'd like to provide more information, but I don't know where to start.
I get the feeling that the toLowerCase hides another error.

image

@Huachao
Copy link
Owner

Huachao commented Jun 7, 2018

@lldata can you show me your http file? And do you mean for same http request, after restarting VS Code can succeed?

And when you are in error state, can you succeed sending a simple request in another file like GET https://www.google.com.

Do you have a callstack in this case, and the notificationAlerts.ts is the code from vscode itself

@Huachao Huachao added the bug label Jun 7, 2018
@lldata
Copy link
Author

lldata commented Jun 7, 2018

When I am in the error state ALL requests fail. So I don't think my http file is that important.
I am reluctant to send it since it uses internal API's.

After restarting all requests resume working as expected.

I will attempt to produce a call stack next time I hit the error, but I am not sure how I get it?

@Huachao
Copy link
Owner

Huachao commented Jun 7, 2018

@lldata since retarting can work, maybe it is related to something that keep in memory of the extension lifetime. One thing I can think of is request variable cache. I will continue inspecting this tomorrow.

@lldata
Copy link
Author

lldata commented Jun 7, 2018

Sounds likely. I use request variables extensively. Something related to caching or other mutable state seems very likely. But it might be hard to fix, if you can't reproduce it ;-)

@Huachao
Copy link
Owner

Huachao commented Jun 8, 2018

@lldata I checked all the code used the toLowerCase() method, I can't find any risk code to call this function. And I want to confirm with you for some possibilities.

  • Can you show me all the named requests'(requests that are referenced by other requests) response content type header value. Or even if some of the responses don't have Content-Type header in them?
  • What's your setting value for rest-client.previewOption?
  • Do you use proxy setting rest-client.excludeHostsForProxy?
  • Do ALL requests failed use requests, if so, try to hover on the references places in request to see if any error occurs.
  • If you don't send any request, just open the http file, will the same error happens?

Thanks in advance.

@lldata
Copy link
Author

lldata commented Jun 8, 2018

  • I have never noticed a response without Content-Type header. I am pretty sure we have that always.
  • "rest-client.previewOption": "full" (default)
  • Yes! We use a proxy server
  • The errors only occurs when I click the request links

When I first got the error some time ago, I dived into the VSCode debugger and caught the error there.
To me it looks like vs code is trying to do a toLowerCase on something - presumably an error from a lower layer. I'll try to catch it again, when I see it next time.

@Huachao
Copy link
Owner

Huachao commented Jun 8, 2018

@lldata so do you mean the error actually happens in the code from VSCode, not from my extension directly?

@lldata
Copy link
Author

lldata commented Jun 8, 2018

From the debug session my impression was that the toLowerCase call was somewhere in the VSCode code base. But to me it looked like there was a different error below.
Also it only happens when I use the rest-client and only when I click "Send request".
I think it is safe to assume that the error is in your plugin. But it might not be in a toLowerCase call.
Look for mutable state. Variables. Request caches. Race conditions.

@Huachao
Copy link
Owner

Huachao commented Jun 8, 2018

@lldata how did you go into the debug session of vscode? Do all requests reference the same request? BTW, can you try to copy the request as cURL(right click for the selected request) when you meet the situation again and check if any error occurs.

@lldata
Copy link
Author

lldata commented Jun 11, 2018

I managed to reproduce it and get this Call Stack:

e.onDidNotificationChange (notificationsAlerts.ts:39) (anonymous) (notificationsAlerts.ts:28) e.fire (event.ts:140) e.notify (notifications.ts:127) e.notify (notificationService.ts:65) (anonymous) (mainThreadMessageService.ts:86) e._showMessage (mainThreadMessageService.ts:47) e.$showMessage (mainThreadMessageService.ts:41) e._doInvokeHandler (rpcProtocol.ts:174) e._invokeHandler (rpcProtocol.ts:159) e._receiveRequest (rpcProtocol.ts:108) e._receiveOneMessage (rpcProtocol.ts:90) (anonymous) (rpcProtocol.ts:33) (anonymous) (rpcProtocol.ts:213) e.fire (event.ts:140) (anonymous) (ipc.net.ts:81) emitOne (events.js:96) emit (events.js:191) readableAddChunk (_stream_readable.js:178) Readable.push (_stream_readable.js:136) onread (net.js:560)

image

@lldata
Copy link
Author

lldata commented Jun 11, 2018

I just spent some time browsing around the debugger. It seems that the question is: who calls onread.
I think some kind of event/exception is emitted from some code that does not show up in the Call Stack.
"onread" in net.js is an event handler.

About the only useful thing I could find is that the event is from the restclient plugin:
image

@Huachao
Copy link
Owner

Huachao commented Jun 11, 2018

@lldata Uhh... Thanks for your help. And can you have a clear repro step for me to help me to investigate? Like showing me after sending a request 'A' and then request 'B' will no longer work until you restart vscode.

@lldata
Copy link
Author

lldata commented Jun 11, 2018

I am sorry. I can't reproduce it at will.
It just happens - then I restart and it works again ..

@Huachao
Copy link
Owner

Huachao commented Jun 29, 2018

@lldata can you try to repro this issue in latest version 0.19.0, and I add some error log in output channel. Thanks in advance.

@lldata
Copy link
Author

lldata commented Jun 29, 2018

Thank you. I have updated and will investigate next time I can reproduce it.

@Huachao
Copy link
Owner

Huachao commented Sep 9, 2018

@lldata did you meet this problem recently?

@lldata
Copy link
Author

lldata commented Sep 9, 2018

Yeah. One of my colleagues got it while I helped him this week.
He was on the latest version.

Only one request in his file didn't work. The others worked fine.
We modied another request in the file, to be exactly the same and that worked.
So I am guessing that the error is somehow connected to the internal state the plugin keeps in relation to a request.

@Huachao
Copy link
Owner

Huachao commented Sep 9, 2018

@lldata next time you meet the issue, please help to check the REST output channel of VSCode, more error details are logged there

@Huachao
Copy link
Owner

Huachao commented Oct 11, 2018

@lldata sorry to bother you again, please help to check if this still happens in latest version like 0.20.2, if yes, please help to inspect the output channel of VSCode with channel name REST. Thanks in advance.

@lldata
Copy link
Author

lldata commented Oct 12, 2018

We managed to reproduce it. My collegues report that they can reproduce it consistently by copying requests from Skype and into a .rest file.

Here is the output from the debug channel:

TypeError: Cannot read property 'toLowerCase' of null
TypeError: Cannot read property 'toLowerCase' of null
	at Function.ignoreProxy (C:\Users\wql\.vscode\extensions\humao.rest-client-0.20.1\out\src\utils\httpClient.js:238:45)
	at HttpClient.<anonymous> (C:\Users\wql\.vscode\extensions\humao.rest-client-0.20.1\out\src\utils\httpClient.js:158:53)
	at Generator.next (<anonymous>)
	at C:\Users\wql\.vscode\extensions\humao.rest-client-0.20.1\out\src\utils\httpClient.js:7:71
	at new Promise (<anonymous>)
	at __awaiter (C:\Users\wql\.vscode\extensions\humao.rest-client-0.20.1\out\src\utils\httpClient.js:3:12)
	at HttpClient.prepareOptions (C:\Users\wql\.vscode\extensions\humao.rest-client-0.20.1\out\src\utils\httpClient.js:108:16)
	at HttpClient.<anonymous> (C:\Users\wql\.vscode\extensions\humao.rest-client-0.20.1\out\src\utils\httpClient.js:44:40)
	at Generator.next (<anonymous>)
	at C:\Users\wql\.vscode\extensions\humao.rest-client-0.20.1\out\src\utils\httpClient.js:7:71
	at new Promise (<anonymous>)
	at __awaiter (C:\Users\wql\.vscode\extensions\humao.rest-client-0.20.1\out\src\utils\httpClient.js:3:12)
	at HttpClient.send (C:\Users\wql\.vscode\extensions\humao.rest-client-0.20.1\out\src\utils\httpClient.js:43:16)
	at RequestController.<anonymous> (C:\Users\wql\.vscode\extensions\humao.rest-client-0.20.1\out\src\controllers\requestController.js:126:55)
	at Generator.next (<anonymous>)
	at C:\Users\wql\.vscode\extensions\humao.rest-client-0.20.1\out\src\controllers\requestController.js:13:71
	at new Promise (<anonymous>)
	at __awaiter (C:\Users\wql\.vscode\extensions\humao.rest-client-0.20.1\out\src\controllers\requestController.js:9:12)
	at RequestController.runCore (C:\Users\wql\.vscode\extensions\humao.rest-client-0.20.1\out\src\controllers\requestController.js:119:16)
	at RequestController.<anonymous> (C:\Users\wql\.vscode\extensions\humao.rest-client-0.20.1\out\src\controllers\requestController.js:94:24)
	at Generator.next (<anonymous>)
	at fulfilled (C:\Users\wql\.vscode\extensions\humao.rest-client-0.20.1\out\src\controllers\requestController.js:10:58)
	at <anonymous>

@Huachao
Copy link
Owner

Huachao commented Oct 12, 2018

@lldata Thanks so much @lldata. I can reproduce this issue as illustrated in the call stack, which needs to meet all the following three preconditions:

  1. Set the http.proxy setting
  2. Set the rest-client.excludeHostsForProxy setting
  3. The request url is not in a well defined format, like missing protocol, etc.,

Anyway, I will fix this issue ASAP to handle this case. Really a nice catch 👍

@Huachao
Copy link
Owner

Huachao commented Oct 12, 2018

@lldata I will publish this fix in next release.

@lldata
Copy link
Author

lldata commented Oct 12, 2018

Amazing feedback time 💯 👍

Thank you for your work!

@Huachao
Copy link
Owner

Huachao commented Nov 1, 2018

@lldata I have published the new version 0.20.3, and you can verify it. And if you still meet this issue, don't hesitate to contact me.

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

No branches or pull requests

2 participants