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

[uncaught exception]: TypeError: this._state.then is not a function #38360

Closed
mjbvz opened this issue Nov 15, 2017 · 4 comments · Fixed by #38362
Closed

[uncaught exception]: TypeError: this._state.then is not a function #38360

mjbvz opened this issue Nov 15, 2017 · 4 comments · Fixed by #38362
Assignees
Labels
important Issue identified as high-priority
Milestone

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Nov 15, 2017

Steps to Reproduce:

On MacOS with Node 7.8

  1. Clone master
  2. Do clean install and build
  3. Open editor. Try opening a file

Bug
Cannot open any files. See [uncaught exception]: TypeError: this._state.then is not a function errors

A bisect identifies f24ea58 as the cause of this

@mjbvz mjbvz added the important Issue identified as high-priority label Nov 15, 2017
@mjbvz
Copy link
Contributor Author

mjbvz commented Nov 15, 2017

Both @rebornix and I have hit this.

I think this line where we call Promise.resolve(detectMimeAndEncodingFromBuffer(...)) may be the root cause of the problem

@rebornix
Copy link
Member

After reading #32381 (comment) I suppose Promise/TPromise is the thing.

mjbvz added a commit to mjbvz/vscode that referenced this issue Nov 15, 2017
`detectMimeAndEncodingFromBuffer` returns a `TPromise<X> | X`. Seems we need to use `TPromise.resolve`to wrap this instead

Fixes microsoft#38360
@mjbvz
Copy link
Contributor Author

mjbvz commented Nov 15, 2017

Root cause of this seems to be that:

  1. detectMimeAndEncodingFromBuffer returns a TPromise
  2. When this TPromise is resolved, it swaps out its .then method.
  3. At this point, I believe Promise.resolve has already grabbed the old .then implementation. It then invokes this invalid .thenlater on, triggering this error

Tested this by changing the code to:

const p: any = detectMimeAndEncodingFromBuffer(
    { buffer: chunkBuffer, bytesRead },
    options && options.autoGuessEncoding || this.configuredAutoGuessEncoding(resource));
Promise.resolve(p.then ?
    ({ then: (x) => p.then(x) })
    : p)

This does seem to work

@jrieken jrieken added this to the November 2017 milestone Nov 15, 2017
@jrieken
Copy link
Member

jrieken commented Nov 15, 2017

😱 wow... Stupid WinJS.Promise...

@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 30, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
important Issue identified as high-priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants