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

TypeError: Cannot read property 'kind' of undefined in 'Object.isImportClause' during 'getCodeFixes' #33726

Closed
typescript-bot opened this issue Oct 1, 2019 · 16 comments · Fixed by #42968
Assignees
Labels
Bug A bug in TypeScript Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fix Available A PR has been opened for this issue Help Wanted You can do this Impact: Failed LS Operation Needs More Info The issue still hasn't been fully clarified Rescheduled This issue was previously scheduled to an earlier milestone Source: Telemetry The issue relates to the telemetry in editors

Comments

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 1, 2019

This issue comes from crash dumps in telemetry. We've tried to de-duplicate issues on a best-effort basis, comparing the sequence of methods called and the command requested while ignoring line numbers.
TypeScript version prefix: 3.6.3
VSCode version: 1.39.0-insider
Command requested: getCodeFixes
Hitting sessions: 113
Five line hash: c7b31f0235de8b834885fd9d3296b6fc
Stack:

    at isImportClause (tsserver.js:14387:21)
    at deleteDeclaration (tsserver.js:115707:32)
    at _loop_9 (tsserver.js:115268:47)
    at ChangeTracker.finishDeleteDeclarations (tsserver.js:115275:21)
    at ChangeTracker.getChanges (tsserver.js:115295:22)
    at ChangeTracker.with (tsserver.js:114832:32)
    at getCodeActions (tsserver.js:119846:69)
    at <anonymous> (tsserver.js:115852:121)
    at flatMap (tsserver.js:583:25)
    at getFixes (tsserver.js:115852:23)
    at <anonymous> (tsserver.js:125866:35)
    at flatMap (tsserver.js:583:25)
    at getCodeFixesAtPosition (tsserver.js:125864:23)
    at unknown (suppressed.js)
    at unknown (suppressed.js)
    at Session.getCodeFixes (tsserver.js:135063:64)
    at _a.<computed> (tsserver.js:133850:61)
    at <anonymous> (tsserver.js:135256:88)
    at Session.executeWithRequestId (tsserver.js:135247:28)
    at Session.executeCommand (tsserver.js:135256:33)
    at Session.onMessage (tsserver.js:135279:35)
    at <anonymous> (tsserver.js:136594:27)
    at unknown (suppressed.js)
    at unknown (suppressed.js)
    at unknown (suppressed.js)
    at unknown (suppressed.js)
    at unknown (suppressed.js)
    at unknown (suppressed.js)
    at unknown (suppressed.js)
    at unknown (suppressed.js)
    at unknown (suppressed.js)
@typescript-bot typescript-bot added Bug A bug in TypeScript Source: Telemetry The issue relates to the telemetry in editors labels Oct 1, 2019
@typescript-bot
Copy link
Collaborator Author

This issue reproduced in the following context:
TypeScript version prefix: 3.7.4
VSCode version: 1.41.1
Command requested: getCodeFixes
Hitting sessions: 101
Five line hash: 78fdd8e690f5ae090e90d0c72b57397c
Stack:

TypeError: Cannot read property 'kind' of undefined
    at Object.isImportClause (tsserver.js:15451:21)
    at Object.deleteDeclaration (tsserver.js:120258:32)
    at _loop_9 (tsserver.js:119812:47)
    at ChangeTracker.finishDeleteDeclarations (tsserver.js:119819:21)
    at ChangeTracker.getChanges (tsserver.js:119839:22)
    at Function.ChangeTracker.with (tsserver.js:119363:32)
    at Object.getCodeActions (tsserver.js:124862:69)
    at unknown (tsserver.js:120403:121)
    at Object.flatMap (tsserver.js:468:25)
    at Object.getFixes (tsserver.js:120403:23)
    at unknown (tsserver.js:131086:35)
    at Object.flatMap (tsserver.js:468:25)
    at Object.getCodeFixesAtPosition (tsserver.js:131084:23)
    at IOSession.Session.getCodeFixes (tsserver.js:140739:64)
    at Session.handlers.ts.createMapFromTemplate._a.<computed> (tsserver.js:139524:61)
    at unknown (tsserver.js:140932:88)
    at IOSession.Session.executeWithRequestId (tsserver.js:140923:28)
    at IOSession.Session.executeCommand (tsserver.js:140932:33)
    at IOSession.Session.onMessage (tsserver.js:140955:35)
    at Interface.<anonymous> (tsserver.js:142270:27)
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()

@typescript-bot
Copy link
Collaborator Author

This issue reproduced in the following context:
TypeScript version prefix: 3.7.5
VSCode version: 1.41.0
Command requested: getCodeFixes
Hitting sessions: 118
Five line hash: 78fdd8e690f5ae090e90d0c72b57397c
Stack:

TypeError: Cannot read property 'kind' of undefined
    at Object.isImportClause (tsserver.js:15455:21)
    at Object.deleteDeclaration (tsserver.js:120286:32)
    at _loop_9 (tsserver.js:119840:47)
    at ChangeTracker.finishDeleteDeclarations (tsserver.js:119847:21)
    at ChangeTracker.getChanges (tsserver.js:119867:22)
    at Function.ChangeTracker.with (tsserver.js:119391:32)
    at Object.getCodeActions (tsserver.js:124890:69)
    at unknown (tsserver.js:120431:121)
    at Object.flatMap (tsserver.js:468:25)
    at Object.getFixes (tsserver.js:120431:23)
    at unknown (tsserver.js:131114:35)
    at Object.flatMap (tsserver.js:468:25)
    at Object.getCodeFixesAtPosition (tsserver.js:131112:23)
    at suppressed_frame()
    at suppressed_frame()
    at IOSession.Session.getCodeFixes (tsserver.js:140767:64)
    at Session.handlers.ts.createMapFromTemplate._a.<computed> (tsserver.js:139552:61)
    at unknown (tsserver.js:140960:88)
    at IOSession.Session.executeWithRequestId (tsserver.js:140951:28)
    at IOSession.Session.executeCommand (tsserver.js:140960:33)
    at IOSession.Session.onMessage (tsserver.js:140983:35)
    at Interface.<anonymous> (tsserver.js:142298:27)
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()

@alexdima
Copy link
Member

Here is a consistent repro from microsoft/monaco-editor#1779 (just paste in the TS playground):

import {Event, Context} from "lambda";
import {Item, Result} from "models";
import * as R from "ramda";

@DanielRosenwasser DanielRosenwasser added Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this Impact: Failed LS Operation labels Feb 12, 2020
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 3.9.0 milestone Feb 12, 2020
@typescript-bot
Copy link
Collaborator Author

This issue reproduced in the following context:
TypeScript version prefix: 3.8.3
VSCode version: 1.42.1
Command requested: getCodeFixes
Hitting sessions: 170
Five line hash: 78fdd8e690f5ae090e90d0c72b57397c
Stack:

TypeError: Cannot read property 'kind' of undefined
    at Object.isImportClause (tsserver.js:11329:21)
    at Object.deleteDeclaration (tsserver.js:124377:32)
    at _loop_9 (tsserver.js:123906:47)
    at ChangeTracker.finishDeleteDeclarations (tsserver.js:123913:21)
    at ChangeTracker.getChanges (tsserver.js:123933:22)
    at Function.ChangeTracker.with (tsserver.js:123414:32)
    at Object.getCodeActions (tsserver.js:129210:69)
    at unknown (tsserver.js:124540:77)
    at Object.flatMap (tsserver.js:465:25)
    at Object.getFixes (tsserver.js:124540:23)
    at unknown (tsserver.js:135666:35)
    at Object.flatMap (tsserver.js:465:25)
    at Proxy.getCodeFixesAtPosition (tsserver.js:135664:23)
    at IOSession.Session.getCodeFixes (tsserver.js:145753:64)
    at Session.handlers.ts.createMapFromTemplate._a.<computed> (tsserver.js:144510:61)
    at unknown (tsserver.js:146003:88)
    at IOSession.Session.executeWithRequestId (tsserver.js:145994:28)
    at IOSession.Session.executeCommand (tsserver.js:146003:33)
    at IOSession.Session.onMessage (tsserver.js:146027:35)
    at Interface.<anonymous> (tsserver.js:147342:27)
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()
    at suppressed_frame()

@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label May 20, 2020
@elibarzilay
Copy link
Contributor

I tried to reproduce this in many ways, but couldn't reproduce it in a useful way, so a reliable local repro is needed.

  • I can see it happening on the playground, but I see the same error for import x from "x" and even import x from x, so I suspect that this is due to some problem in there.

  • I tried locally in vscode, and directly sending a getCodeFixes command in Emacs, and did that with a bunch of different versions, but couldn't reproduce it.

@elibarzilay elibarzilay added the Needs More Info The issue still hasn't been fully clarified label Jun 18, 2020
@typescript-bot
Copy link
Collaborator Author

Revised stack format and updated hash.

@andrewbranch
Copy link
Member

andrewbranch commented Jul 9, 2020

The client has to be sending a bad error span in the request—whatever the root cause is, it’s almost definitely going to be the same root cause as #32856.

It repros reliably in the playground because of a monaco-typescript bug.

@jpinilloslr
Copy link

Same issue with export.

  1. Open the Monaco Editor homepage: https://microsoft.github.io/monaco-editor/
  2. Select javascript or typescript language.
  3. Paste this code:
export const foo = 1;
const bar

Actual result: The following error is printed to the browser console:

Uncaught Error: Cannot read property 'kind' of undefined

TypeError: Cannot read property 'kind' of undefined
    at Object.e.isImportClause (tsWorker.js:21)
    at Object.n.deleteDeclaration (tsWorker.js:21)
    at r (tsWorker.js:21)
    at n.finishDeleteDeclarations (tsWorker.js:21)
    at n.getChanges (tsWorker.js:21)
    at Function.n.with (tsWorker.js:21)
    at Object.getCodeActions (tsWorker.js:21)
    at tsWorker.js:21
    at Object.e.flatMap (tsWorker.js:21)
    at Object.n.getFixes (tsWorker.js:21)
    at errors.ts:22

@typescript-bot
Copy link
Collaborator Author

This issue reproduced in the following context:
TypeScript version prefix: 3.9.7
VSCode version: 1.48.0-insider
Command requested: getCodeFixes
Hitting sessions: 196
Five line hash: c7b31f0235de8b834885fd9d3296b6fc
Stack:

    at isImportClause (tsserver.js:11638:21)
    at deleteDeclaration (tsserver.js:127231:32)
    at _loop_9 (tsserver.js:126742:47)
    at ChangeTracker.finishDeleteDeclarations (tsserver.js:126749:21)
    at ChangeTracker.getChanges (tsserver.js:126769:22)
    at ChangeTracker.with (tsserver.js:126224:32)
    at getCodeActions (tsserver.js:131598:69)
    at <anonymous> (tsserver.js:127394:77)
    at flatMap (tsserver.js:465:25)
    at getFixes (tsserver.js:127394:23)
    at <anonymous> (tsserver.js:139206:35)
    at flatMap (tsserver.js:465:25)
    at getCodeFixesAtPosition (tsserver.js:139204:23)
    at Session.getCodeFixes (tsserver.js:149305:64)
    at _a.<computed> (tsserver.js:148042:61)
    at <anonymous> (tsserver.js:149555:88)
    at Session.executeWithRequestId (tsserver.js:149546:28)
    at Session.executeCommand (tsserver.js:149555:33)
    at Session.onMessage (tsserver.js:149579:35)
    at <anonymous> (tsserver.js:150895:27)
    at unknown (suppressed.js:223:5)
    at unknown (suppressed.js:315:10)
    at unknown (suppressed.js:460:12)
    at unknown (suppressed.js:172:10)
    at unknown (suppressed.js:223:5)
    at unknown (suppressed.js:309:12)
    at unknown (suppressed.js:290:11)
    at unknown (suppressed.js:224:10)
    at unknown (suppressed.js:181:23)

@typescript-bot
Copy link
Collaborator Author

This issue reproduced in the following context:
TypeScript version prefix: 4.0.2
VSCode version: 1.48.1
Command requested: getCodeFixes
Hitting sessions: 182
Five line hash: c7b31f0235de8b834885fd9d3296b6fc
Stack:

    at isImportClause (tsserver.js:25782:21)
    at deleteDeclaration (tsserver.js:130428:32)
    at _loop_9 (tsserver.js:129941:47)
    at ChangeTracker.finishDeleteDeclarations (tsserver.js:129948:21)
    at ChangeTracker.getChanges (tsserver.js:129968:22)
    at ChangeTracker.with (tsserver.js:129419:32)
    at getCodeActions (tsserver.js:135018:69)
    at <anonymous> (tsserver.js:130591:77)
    at flatMap (tsserver.js:513:25)
    at getFixes (tsserver.js:130591:23)
    at <anonymous> (tsserver.js:143788:35)
    at flatMap (tsserver.js:513:25)
    at getCodeFixesAtPosition (tsserver.js:143786:23)
    at unknown (suppressed.js:170:34)
    at unknown (suppressed.js:77:25)
    at Session.getCodeFixes (tsserver.js:154654:64)
    at _a.<computed> (tsserver.js:153331:61)
    at <anonymous> (tsserver.js:154953:88)
    at Session.executeWithRequestId (tsserver.js:154944:28)
    at Session.executeCommand (tsserver.js:154953:33)
    at Session.onMessage (tsserver.js:154977:35)
    at <anonymous> (tsserver.js:157193:27)
    at unknown (suppressed.js:203:13)
    at unknown (suppressed.js:316:10)
    at unknown (suppressed.js:461:12)
    at unknown (suppressed.js:172:10)
    at unknown (suppressed.js:203:13)
    at unknown (suppressed.js:295:12)
    at unknown (suppressed.js:276:11)
    at unknown (suppressed.js:210:10)
    at unknown (suppressed.js:166:17)

@typescript-bot
Copy link
Collaborator Author

This issue reproduced in the following context:
TypeScript version prefix: 4.0.3
VSCode version: 1.50.0-insider
Command requested: getCodeFixes
Hitting sessions: 132
Five line hash: c7b31f0235de8b834885fd9d3296b6fc
Stack:

    at isImportClause (tsserver.js:25789:21)
    at deleteDeclaration (tsserver.js:130436:32)
    at _loop_9 (tsserver.js:129949:47)
    at ChangeTracker.finishDeleteDeclarations (tsserver.js:129956:21)
    at ChangeTracker.getChanges (tsserver.js:129976:22)
    at ChangeTracker.with (tsserver.js:129426:32)
    at getCodeActions (tsserver.js:135026:69)
    at <anonymous> (tsserver.js:130599:77)
    at flatMap (tsserver.js:513:25)
    at getFixes (tsserver.js:130599:23)
    at <anonymous> (tsserver.js:143796:35)
    at flatMap (tsserver.js:513:25)
    at getCodeFixesAtPosition (tsserver.js:143794:23)
    at unknown (suppressed.js:170:34)
    at unknown (suppressed.js:77:25)
    at Session.getCodeFixes (tsserver.js:154662:64)
    at _a.<computed> (tsserver.js:153339:61)
    at <anonymous> (tsserver.js:154962:88)
    at Session.executeWithRequestId (tsserver.js:154953:28)
    at Session.executeCommand (tsserver.js:154962:33)
    at Session.onMessage (tsserver.js:154986:35)
    at <anonymous> (tsserver.js:157202:27)
    at unknown (suppressed.js:223:5)
    at unknown (suppressed.js:315:10)
    at unknown (suppressed.js:460:12)
    at unknown (suppressed.js:172:10)
    at unknown (suppressed.js:223:5)
    at unknown (suppressed.js:309:12)
    at unknown (suppressed.js:290:11)
    at unknown (suppressed.js:224:10)
    at unknown (suppressed.js:181:23)

@typescript-bot
Copy link
Collaborator Author

This issue reproduced in the following context:
TypeScript version prefix: 4.1.2
VSCode version: 1.51.1
Command requested: getCodeFixes
Hitting sessions: 262
Five line hash: c7b31f0235de8b834885fd9d3296b6fc
Stack:

    at isImportClause (tsserver.js:26605:21)
    at deleteDeclaration (tsserver.js:133365:32)
    at _loop_9 (tsserver.js:132873:47)
    at ChangeTracker.finishDeleteDeclarations (tsserver.js:132880:21)
    at ChangeTracker.getChanges (tsserver.js:132900:22)
    at ChangeTracker.with (tsserver.js:132350:32)
    at getCodeActions (tsserver.js:138109:69)
    at <anonymous> (tsserver.js:133528:77)
    at flatMap (tsserver.js:513:25)
    at getFixes (tsserver.js:133528:23)
    at <anonymous> (tsserver.js:147037:35)
    at flatMap (tsserver.js:513:25)
    at getCodeFixesAtPosition (tsserver.js:147035:23)
    at Session.getCodeFixes (tsserver.js:157976:64)
    at _a.<computed> (tsserver.js:156653:61)
    at <anonymous> (tsserver.js:158276:88)
    at Session.executeWithRequestId (tsserver.js:158267:28)
    at Session.executeCommand (tsserver.js:158276:33)
    at Session.onMessage (tsserver.js:158300:35)
    at <anonymous> (tsserver.js:160510:27)
    at unknown (suppressed.js:223:5)
    at unknown (suppressed.js:315:10)
    at unknown (suppressed.js:460:12)
    at unknown (suppressed.js:172:10)
    at unknown (suppressed.js:223:5)
    at unknown (suppressed.js:309:12)
    at unknown (suppressed.js:290:11)
    at unknown (suppressed.js:224:10)
    at unknown (suppressed.js:181:23)

@typescript-bot
Copy link
Collaborator Author

This issue reproduced in the following context:
TypeScript version prefix: 4.1.3
VSCode version: 1.52.1
Command requested: getCodeFixes
Hitting sessions: 110
Five line hash: c7b31f0235de8b834885fd9d3296b6fc
Stack:

    at isImportClause (tsserver.js:26605:21)
    at deleteDeclaration (tsserver.js:133367:32)
    at _loop_9 (tsserver.js:132875:47)
    at ChangeTracker.finishDeleteDeclarations (tsserver.js:132882:21)
    at ChangeTracker.getChanges (tsserver.js:132902:22)
    at ChangeTracker.with (tsserver.js:132352:32)
    at getCodeActions (tsserver.js:138111:69)
    at <anonymous> (tsserver.js:133530:77)
    at flatMap (tsserver.js:513:25)
    at getFixes (tsserver.js:133530:23)
    at <anonymous> (tsserver.js:147039:35)
    at flatMap (tsserver.js:513:25)
    at getCodeFixesAtPosition (tsserver.js:147037:23)
    at Session.getCodeFixes (tsserver.js:157982:64)
    at _a.<computed> (tsserver.js:156659:61)
    at <anonymous> (tsserver.js:158282:88)
    at Session.executeWithRequestId (tsserver.js:158273:28)
    at Session.executeCommand (tsserver.js:158282:33)
    at Session.onMessage (tsserver.js:158306:35)
    at <anonymous> (tsserver.js:160516:27)
    at unknown (suppressed.js:223:5)
    at unknown (suppressed.js:315:10)
    at unknown (suppressed.js:460:12)
    at unknown (suppressed.js:172:10)
    at unknown (suppressed.js:223:5)
    at unknown (suppressed.js:309:12)
    at unknown (suppressed.js:290:11)
    at unknown (suppressed.js:224:10)
    at unknown (suppressed.js:181:23)

@typescript-bot
Copy link
Collaborator Author

This issue reproduced in the following context:
TypeScript version prefix: 4.1.5
VSCode version: 1.53.2
Command requested: getCodeFixes
Hitting sessions: 2457
Five line hash: c7b31f0235de8b834885fd9d3296b6fc
Stack:

    at isImportClause (tsserver.js:26605:21)
    at deleteDeclaration (tsserver.js:133367:32)
    at _loop_9 (tsserver.js:132875:47)
    at ChangeTracker.finishDeleteDeclarations (tsserver.js:132882:21)
    at ChangeTracker.getChanges (tsserver.js:132902:22)
    at ChangeTracker.with (tsserver.js:132352:32)
    at getCodeActions (tsserver.js:138111:69)
    at <anonymous> (tsserver.js:133530:77)
    at flatMap (tsserver.js:513:25)
    at getFixes (tsserver.js:133530:23)
    at <anonymous> (tsserver.js:147039:35)
    at flatMap (tsserver.js:513:25)
    at getCodeFixesAtPosition (tsserver.js:147037:23)
    at unknown (suppressed.js:178:34)
    at unknown (suppressed.js:79:25)
    at Session.getCodeFixes (tsserver.js:157986:64)
    at _a.<computed> (tsserver.js:156663:61)
    at <anonymous> (tsserver.js:158286:88)
    at Session.executeWithRequestId (tsserver.js:158277:28)
    at Session.executeCommand (tsserver.js:158286:33)
    at Session.onMessage (tsserver.js:158310:35)
    at <anonymous> (tsserver.js:160520:27)
    at unknown (suppressed.js:315:20)
    at unknown (suppressed.js:329:10)
    at unknown (suppressed.js:474:12)
    at unknown (suppressed.js:186:10)
    at unknown (suppressed.js:315:20)
    at unknown (suppressed.js:295:12)
    at unknown (suppressed.js:271:9)
    at unknown (suppressed.js:212:10)
    at unknown (suppressed.js:186:23)

elibarzilay added a commit to elibarzilay/TypeScript that referenced this issue Feb 25, 2021
A misbehaved client can sometimes cause the server to reach
`deleteDeclaration` with the SourceFile, and it will crash due to no
`node.parent`.  I couldn't find a good way to create a test for it, but
I could trigger it manually by having a file with just a `,`, and
sending an explicit `getCodeFixes` command to the server with
`errorCodes: [6133]`.

I can only guess some scenario in which Emacs or other editors could
lead to that, but it's easy to just avoid the crash instead.  (Doing the
default of deleting the whole thing -- not really important since it's a
broken client situation anyway--?)

Fixes microsoft#33726
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Feb 25, 2021
elibarzilay added a commit to elibarzilay/TypeScript that referenced this issue Feb 26, 2021
A misbehaved client can sometimes cause the server to reach
`deleteDeclaration` with the SourceFile, and it will crash due to no
`node.parent`.  I couldn't find a good way to create a test for it, but
I could trigger it manually by having a file with just a `,`, and
sending an explicit `getCodeFixes` command to the server with
`errorCodes: [6133]`.

I can only guess some scenario in which Emacs or other editors could
lead to that, but it's easy to just avoid the crash instead.  (Doing the
default of deleting the whole thing -- not really important since it's a
broken client situation anyway--?)

Fixes microsoft#33726
@typescript-bot
Copy link
Collaborator Author

This issue reproduced in the following context:
TypeScript version prefix: 4.2.3
VSCode version: 1.54.2
Command requested: getCodeFixes
Hitting sessions: 3079
Five line hash: c7b31f0235de8b834885fd9d3296b6fc
Stack:

    at isImportClause (tsserver.js:26960:21)
    at deleteDeclaration (tsserver.js:135328:32)
    at _loop_9 (tsserver.js:134836:47)
    at ChangeTracker.finishDeleteDeclarations (tsserver.js:134843:21)
    at ChangeTracker.getChanges (tsserver.js:134863:22)
    at ChangeTracker.with (tsserver.js:134318:32)
    at getCodeActions (tsserver.js:140211:69)
    at <anonymous> (tsserver.js:135491:77)
    at flatMap (tsserver.js:515:25)
    at getFixes (tsserver.js:135491:23)
    at <anonymous> (tsserver.js:149557:35)
    at flatMap (tsserver.js:515:25)
    at getCodeFixesAtPosition (tsserver.js:149555:23)
    at Session.getCodeFixes (tsserver.js:160663:64)
    at _a.<computed> (tsserver.js:159335:61)
    at <anonymous> (tsserver.js:160963:88)
    at Session.executeWithRequestId (tsserver.js:160954:28)
    at Session.executeCommand (tsserver.js:160963:33)
    at Session.onMessage (tsserver.js:160989:35)
    at <anonymous> (tsserver.js:163650:31)
    at unknown (suppressed.js:315:20)
    at unknown (suppressed.js:329:10)
    at unknown (suppressed.js:474:12)
    at unknown (suppressed.js:186:10)
    at unknown (suppressed.js:315:20)
    at unknown (suppressed.js:295:12)
    at unknown (suppressed.js:271:9)
    at unknown (suppressed.js:212:10)
    at unknown (suppressed.js:186:23)

elibarzilay added a commit to elibarzilay/TypeScript that referenced this issue Mar 22, 2021
A misbehaved client can sometimes cause the server to reach
`deleteDeclaration` with the SourceFile, and it will crash due to no
`node.parent`.  I couldn't find a good way to create a test for it, but
I could trigger it manually by having a file with just a `,`, and
sending an explicit `getCodeFixes` command to the server with
`errorCodes: [6133]`.

Do three things to improve this:

1. `textChanges.ts`: if we get here with the root node, delete it
   instead of failing.

2. `fixUnusedIdentifier.ts`: check that we don't `delete` a node that is
   the whole source file, so the error is more focused (should have more
   similar failure stacks).

3. `session.ts`: when there was any failure in `getCodeFixes`, check if
   the input had a diag code that does not appear in the requested text
   range, and throw an error saying that the failure is probably a
   result of a bad request.

Fixes microsoft#33726
elibarzilay added a commit to elibarzilay/TypeScript that referenced this issue Mar 22, 2021
A misbehaved client can sometimes cause the server to reach
`deleteDeclaration` with the SourceFile, and it will crash due to no
`node.parent`.  I couldn't find a good way to create a test for it, but
I could trigger it manually by having a file with just a `,`, and
sending an explicit `getCodeFixes` command to the server with
`errorCodes: [6133]`.

Do three things to improve this:

1. `textChanges.ts`: if we get here with the root node, delete it
   instead of failing.

2. `fixUnusedIdentifier.ts`: check that we don't `delete` a node that is
   the whole source file, so the error is more focused (should have more
   similar failure stacks).

3. `session.ts`: when there was any failure in `getCodeFixes`, check if
   the input had a diag code that does not appear in the requested text
   range, and throw an error saying that the failure is probably a
   result of a bad request.

Closes microsoft#33726 (probably not fixing it, but making it easier to find the
cause)
elibarzilay added a commit to elibarzilay/TypeScript that referenced this issue Mar 23, 2021
A misbehaved client can sometimes cause the server to reach
`deleteDeclaration` with the SourceFile, and it will crash due to no
`node.parent`.  I couldn't find a good way to create a test for it, but
I could trigger it manually by having a file with just a `,`, and
sending an explicit `getCodeFixes` command to the server with
`errorCodes: [6133]`.

Do three things to improve this:

1. `textChanges.ts`: if we get here with the root node, delete it
   instead of failing.

2. `fixUnusedIdentifier.ts`: check that we don't `delete` a node that is
   the whole source file, so the error is more focused (should have more
   similar failure stacks).

3. `session.ts`: when there was any failure in `getCodeFixes`, check if
   the input had a diag code that does not appear in the requested text
   range, and throw an error saying that the failure is probably a
   result of a bad request.

Closes microsoft#33726 (probably not fixing it, but making it easier to find the
cause)
elibarzilay added a commit to elibarzilay/TypeScript that referenced this issue Mar 24, 2021
A misbehaved client can sometimes cause the server to reach
`deleteDeclaration` with the SourceFile, and it will crash due to no
`node.parent`.  I couldn't find a good way to create a test for it, but
I could trigger it manually by having a file with just a `,`, and
sending an explicit `getCodeFixes` command to the server with
`errorCodes: [6133]`.

Do three things to improve this:

1. `textChanges.ts`: if we get here with the root node, delete it
   instead of failing.

2. `fixUnusedIdentifier.ts`: check that we don't `delete` a node that is
   the whole source file, so the error is more focused (should have more
   similar failure stacks).

3. `session.ts`: when there was any failure in `getCodeFixes`, check if
   the input had a diag code that does not appear in the requested text
   range, and throw an error saying that the failure is probably a
   result of a bad request.

Closes microsoft#33726 (probably not fixing it, but making it easier to find the
cause)
elibarzilay added a commit that referenced this issue Mar 24, 2021
A misbehaved client can sometimes cause the server to reach
`deleteDeclaration` with the SourceFile, and it will crash due to no
`node.parent`.  I couldn't find a good way to create a test for it, but
I could trigger it manually by having a file with just a `,`, and
sending an explicit `getCodeFixes` command to the server with
`errorCodes: [6133]`.

Do three things to improve this:

1. `textChanges.ts`: if we get here with the root node, delete it
   instead of failing.

2. `fixUnusedIdentifier.ts`: check that we don't `delete` a node that is
   the whole source file, so the error is more focused (should have more
   similar failure stacks).

3. `session.ts`: when there was any failure in `getCodeFixes`, check if
   the input had a diag code that does not appear in the requested text
   range, and throw an error saying that the failure is probably a
   result of a bad request.

Closes #33726 (probably not fixing it, but making it easier to find the
cause)
@typescript-bot
Copy link
Collaborator Author

This issue reproduced in the following context:
TypeScript version prefix: 4.2.4
VSCode version: 1.56.0-insider
Command requested: getCodeFixes
Hitting sessions: 201
Five line hash: c7b31f0235de8b834885fd9d3296b6fc
Stack:

    at isImportClause (tsserver.js:26960:21)
    at deleteDeclaration (tsserver.js:135330:32)
    at _loop_9 (tsserver.js:134838:47)
    at ChangeTracker.finishDeleteDeclarations (tsserver.js:134845:21)
    at ChangeTracker.getChanges (tsserver.js:134865:22)
    at ChangeTracker.with (tsserver.js:134320:32)
    at getCodeActions (tsserver.js:140213:69)
    at <anonymous> (tsserver.js:135493:77)
    at flatMap (tsserver.js:515:25)
    at getFixes (tsserver.js:135493:23)
    at <anonymous> (tsserver.js:149557:35)
    at flatMap (tsserver.js:515:25)
    at getCodeFixesAtPosition (tsserver.js:149555:23)
    at Session.getCodeFixes (tsserver.js:160663:64)
    at _a.<computed> (tsserver.js:159335:61)
    at <anonymous> (tsserver.js:160963:88)
    at Session.executeWithRequestId (tsserver.js:160954:28)
    at Session.executeCommand (tsserver.js:160963:33)
    at Session.onMessage (tsserver.js:160989:35)
    at <anonymous> (tsserver.js:163650:31)
    at unknown (suppressed.js:315:20)
    at unknown (suppressed.js:329:10)
    at unknown (suppressed.js:474:12)
    at unknown (suppressed.js:186:10)
    at unknown (suppressed.js:315:20)
    at unknown (suppressed.js:295:12)
    at unknown (suppressed.js:271:9)
    at unknown (suppressed.js:212:10)
    at unknown (suppressed.js:186:23)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fix Available A PR has been opened for this issue Help Wanted You can do this Impact: Failed LS Operation Needs More Info The issue still hasn't been fully clarified Rescheduled This issue was previously scheduled to an earlier milestone Source: Telemetry The issue relates to the telemetry in editors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants