Skip to content

deleteDeclaration: don't crash on the top node. #42968

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

Merged
merged 1 commit into from
Mar 24, 2021

Conversation

elibarzilay
Copy link
Contributor

@elibarzilay elibarzilay commented 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].

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)

Copy link
Member

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But moreover, we know that this is not from Emacs or fringe editors or general API misuse, because the telemetry comes to us via VS Code. I’m generally not a fan of silencing bugs we don’t understand. I’m not sure this is any better than crashing, because either way, the result is that we don’t generate a codefix. In either case, the user experience is either broken or completely unnoticeable (hard to say which); the only thing this PR does is prevents us from getting telemetry for it anymore.

@microsoft microsoft deleted a comment 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 elibarzilay merged commit 6ce82ab into microsoft:master Mar 24, 2021
@elibarzilay elibarzilay deleted the 33726 branch March 24, 2021 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

TypeError: Cannot read property 'kind' of undefined in 'Object.isImportClause' during 'getCodeFixes'
3 participants