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

Typescript service is often stopping working randomly: Cannot read property 'charCount' of undefined #16456

Closed
mjbvz opened this issue Jun 12, 2017 · 19 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue VS Code Tracked There is a VS Code equivalent to this issue

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Jun 12, 2017

From @asvetliakov on June 12, 2017 16:40

  • VSCode Version: 1.13.0
  • OS Version: macOS 10.12.5

May be related to #28112

I'm not sure how to reproduce it yet. It seems to happen randomly and VERY often.
Steps:

  1. Edit your code (medium to large project)
  2. After some time the ts service stops working:
    2.1. The validation messages are incorrect and have incorrect location
    2.2. Completion and navigation features stops working

Typescript version: 2.3.3, also i didn't have any issues with vscode 1.12.0

I'm getting this in typescript service output:

[Error  - 6:32:24 PM] 'navtree' request failed with error.
Error processing request. Cannot read property 'charCount' of undefined
TypeError: Cannot read property 'charCount' of undefined
    at LineNode.walk (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:78490:47)
    at LineIndex.edit (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:78358:35)
    at ScriptVersionCache.getSnapshot (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:78150:47)
    at TextStorage.getSnapshot (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:73269:32)
    at ScriptInfo.getSnapshot (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:73378:41)
    at LSHost.getScriptSnapshot (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:73648:39)
    at SyntaxTreeCache.getCurrentSourceFile (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:71449:44)
    at Object.getNavigationTree (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:71953:71)
    at IOSession.Session.getNavigationTree (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:77613:62)
    at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:76670:61)

Full log: https://pastebin.com/X6xpSR1z

Thanks

Copied from original issue: microsoft/vscode#28543

@mjbvz
Copy link
Contributor Author

mjbvz commented Jun 12, 2017

Looks like the first failure is:

[Error  - 6:10:16 PM] 'signatureHelp' request failed with error.
Error processing request. Debug Failure. False expression: 
Error: Debug Failure. False expression: 
    at Object.assert (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:2902:23)
    at Object.computePositionOfLineAndCharacter (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:9137:18)
    at TextStorage.lineOffsetToPosition (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:73296:31)
    at ScriptInfo.lineOffsetToPosition (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:73508:41)
    at IOSession.Session.getPosition (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:77280:81)
    at IOSession.Session.getSignatureHelpItems (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:77501:37)
    at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:76599:61)
    at /Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:77820:88
    at IOSession.Session.executeWithRequestId (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:77811:28)
    at IOSession.Session.executeCommand (/Users/asvetl/work/applications/frontend/node_modules/typescript/lib/tsserver.js:77820:33)

(The cancelled requests ones are from vscode and not really errors. I've fixed the logging of these in the current vscode insiders builds)

@mhegazy mhegazy added the Bug A bug in TypeScript label Jun 12, 2017
@mhegazy mhegazy assigned ghost Jun 12, 2017
@mhegazy mhegazy added this to the TypeScript 2.4.1 milestone Jun 12, 2017
@ghost
Copy link

ghost commented Jun 12, 2017

Hi @asvetliakov, what we can tell from the log is that the server is somehow getting into a bad state where the contents of a source file are out-of-sync with line/column information. But we don't know how it got into that state. The attatched log doesn't seem to begin from the launch of the tsserver; that would be indicated if it started like:

Info 0    Binding...
Info 1    request: {"seq":0,"type":"request","command":"configure","arguments":{"hostInfo":"vscode"}}
Info 2    Host information vscode
Info 3    response: {"seq":0,"type":"response","command":"configure","request_seq":0,"success":true}
Perf 4    0::configure: async elapsed time (in milliseconds) 1.3250

Would you be able to get a complete log from the start?
If you don't want it pasted to github, you could also email me at [email protected].

@asvetliakov
Copy link

@Andy-MS Just sent full trace log to your email

@ghost
Copy link

ghost commented Jun 19, 2017

Hi @asvetliakov, that looks like a different log file that what we were expecting.
In VSCode you should be able to open the command palette and choose "TypeScript: Open TS Server Log". This should take you to a directory with a file tsserver.log inside. That should start with the header I mentioned above.

@ghost
Copy link

ghost commented Jun 20, 2017

@asvetliakov Thanks, that looks like the correct one.

@Pajn
Copy link

Pajn commented Jul 7, 2017

I'm having this issue too, do you need additional logs?

@ghost
Copy link

ghost commented Jul 7, 2017

Thanks, we've already reproduced the error.

@ghost
Copy link

ghost commented Jul 12, 2017

@asvetliakov We noticed the following on line 17 of the log you sent us:

Info 16   Add recursive watcher for: /Users/.../projectName
Info 17   Add recursive watcher for: /users/.../projectName/src

Could you check that your file system is case-sensitive? I've adapted the code we use to test for this, so you can put it in any .js file and run:

const os = require("os");
const fs = require("fs");

function fileExists(path) {
    try {
        const stat = fs.statSync(path);
        return stat.isFile();
    }
    catch (e) {
        return false;
    }
}

function isFileSystemCaseSensitive() {
    const platform = os.platform();
    // win32\win64 are case insensitive platforms
    if (platform === "win32" || platform === "win64") {
        return false;
    }
    // convert current file name to upper case / lower case and check if file exists
    // (guards against cases when name is already all uppercase or lowercase)
    return !fileExists(__filename.toUpperCase()) || !fileExists(__filename.toLowerCase());
}

console.log(isFileSystemCaseSensitive());

@Pajn Could you check for something similar, or send us your logs too?

@asvetliakov
Copy link

No, my file system is case-insensitive. Your code gives false output.
Also noticed that this problem always happened after i'd created some new file in project and started to edit it. Happens even in small projects.

@ghost
Copy link

ghost commented Jul 12, 2017

@asvetliakov Could you share your tsconfig.json? Also, logs from a small project would be helpful, especially if you could share steps to create the project. Just in case we need it, what is your OS?

@asvetliakov
Copy link

asvetliakov commented Jul 13, 2017

@Andy-MS
My OS is macOS 12.5 and tsconfig is:

{
    "compilerOptions": {
        "strict": true,
        "strictNullChecks": true,
        "target": "es2016",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "noEmitOnError": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "types": [
            "node",
            "jest"
        ],
        "noUnusedLocals": true,
        "outDir": "./compiled",
        "typeRoots": [
            "types",
            "node_modules/@types"
        ],
        "baseUrl": ".",
        "paths": {
            "*": [
                "types/*"
            ]
        }
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules",
        "compiled"
    ]
}

Also, looks like i can't reproduce it now with the new version of vscode 1.14, so may be error came from vscode side, as i didn't have any problems with version 1.12 too. Should i try to capture logs from vscode 1.13?

@ghost
Copy link

ghost commented Jul 13, 2017

Hi @asvetliakov , I think at this point the specific error we are looking for is when both a /Users and /users directory show up in the logs -- since there should only be /Users (assuming upper-case is the correct name). In the logs we have it looks like that showed up immediately, so it should be easy to tell whether this is still happening. I assume that if you ls /users/.../projectName/src you get an error because no such directory exists?

Also of note, our watcher for "/users" does somehow seem to be getting fired, which is how we end up with duplicate files.

The only file that is giving us problems is named Cookie.ts. The C is always upper-case, but in the log it alternates between /Users/.../Cookie.ts and /users/.../Cookie.ts.
Every other file seems to use an uppercase /Users.

We also seem to be getting vscode some "open" events for lower-case "users", although only after we send it a "configFileDiag" event. (Since apparently we consider the tsconfig for /users/.../Cookie.ts to be different than the one for /Users/.../Cookie.ts, even though the tsconfigs both have the same /Users/.../tsconfig.json path.)

@sheetalkamat Is also refactoring our watch implementation so she might have insight into how we ended up watching a lower-case directory.

@sheetalkamat sheetalkamat self-assigned this Jul 13, 2017
@ghost
Copy link

ghost commented Jul 13, 2017

Based on discussion with @sheetalkamat this may be solved by the new watch implementation.
(Ref: #17269)

@asvetliakov
Copy link

asvetliakov commented Jul 13, 2017

Still have multiple /users in logs for vscode 1.14

Info 16   Add recursive watcher for: /Users/asvetl/work/applications/frontend
Info 17   Add recursive watcher for: /users/asvetl/work/applications/frontend/src
Info 18   Add type root watcher for: /Users/asvetl/work/applications/frontend/types
Info 19   Add type root watcher for: /Users/asvetl/work/applications/frontend/node_modules/@types

I assume that if you ls /users/.../projectName/src you get an error because no such directory exists?

No. Both ls /users/... and ls /Users/... are giving success result (with directory structure)

@Pajn
Copy link

Pajn commented Jul 20, 2017

I'm sorry for not coming back sooner.
The computer where I have seen this error is a mac with a default installation, which means that the file system is case-insensitive. Both ls /users/rasmus and ls /Users/rasmus work fine.

sheetalkamat added a commit that referenced this issue Aug 19, 2017
…e and non sensitive file system and fixing caching
sheetalkamat added a commit that referenced this issue Aug 22, 2017
…e and non sensitive file system and fixing caching
@abenhamdine
Copy link

abenhamdine commented Aug 30, 2017

I am not sure if my problem is exactly the same, but after having added some new files in the project, tsc began to crash with :

C:\node-projects\payroll-app\node_modules\schemats\node_modules\tslint\node_modules\typescript\lib\tsc.js:2062
            throw e;
            ^

Error: Debug Failure. False expression.
    at computePositionOfLineAndCharacter (C:\node-projects\payroll-app\node_modules\schemats\node_modules\tslint\node_modules\typescript\lib\tsc.js:3752:22)
    at Object.getPositionOfLineAndCharacter (C:\node-projects\payroll-app\node_modules\schemats\node_modules\tslint\node_modules\typescript\lib\tsc.js:3742:16)
    at Object.formatDiagnosticsWithColorAndContext (C:\node-projects\payroll-app\node_modules\schemats\node_modules\tslint\node_modules\typescript\lib\tsc.js:55564:59)
    at reportDiagnosticWithColorAndContext (C:\node-projects\payroll-app\node_modules\schemats\node_modules\tslint\node_modules\typescript\lib\tsc.js:58760:25)
    at reportDiagnostic (C:\node-projects\payroll-app\node_modules\schemats\node_modules\tslint\node_modules\typescript\lib\tsc.js:58722:9)
    at reportDiagnostics (C:\node-projects\payroll-app\node_modules\schemats\node_modules\tslint\node_modules\typescript\lib\tsc.js:58727:13)
    at compileProgram (C:\node-projects\payroll-app\node_modules\schemats\node_modules\tslint\node_modules\typescript\lib\tsc.js:59088:13)
    at compile (C:\node-projects\payroll-app\node_modules\schemats\node_modules\tslint\node_modules\typescript\lib\tsc.js:59040:26)
    at performCompilation (C:\node-projects\payroll-app\node_modules\schemats\node_modules\tslint\node_modules\typescript\lib\tsc.js:58929:33)
    at Object.executeCommandLine (C:\node-projects\payroll-app\node_modules\schemats\node_modules\tslint\node_modules\typescript\lib\tsc.js:58872:9)
    at Object.<anonymous> (C:\node-projects\payroll-app\node_modules\schemats\node_modules\tslint\node_modules\typescript\lib\tsc.js:59230:4)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Module.require (module.js:517:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\node-projects\payroll-app\node_modules\schemats\node_modules\tslint\node_modules\typescript\bin\tsc:2:1)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:598:3

Tsc : 2.5.1 and 2.6.0-dev.20170829
Windows 10 64 bits
Nodejs 8.4.0

I can provide ts server log if need be.

@sheetalkamat
Copy link
Member

Can you please give a try to typescript@next to see if this works. I believe this with merge of PR #17669

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Oct 4, 2017
@mhegazy mhegazy closed this as completed Oct 4, 2017
@abenhamdine
Copy link

I haven't seen the issue any more after upgrading to 2.5.2

@sparr
Copy link

sparr commented Oct 26, 2017

For posterity, I'm still seeing the "Debug Failure. False expression. at computePositionOfLineAndCharacter" error with 2.5.3 on OSX Sierra, but the problem is fixed in typescript@next so I'm not opening a new issue.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue VS Code Tracked There is a VS Code equivalent to this issue
Projects
None yet
Development

No branches or pull requests

8 participants