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

Truncate lineText in references responses to avoid RangeError #50134

Closed
amcasey opened this issue Aug 1, 2022 · 3 comments
Closed

Truncate lineText in references responses to avoid RangeError #50134

amcasey opened this issue Aug 1, 2022 · 3 comments
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@amcasey
Copy link
Member

amcasey commented Aug 1, 2022

Repro

Present in 4.7.4. and main.

  1. git clone https://github.com/apache/echarts
  2. cd echarts
  3. git reset --hard c58437740899254aeb318595d4e5e324ad48961d
  4. cd ..
  5. npm install @typescript/server-replay
  6. Download replay.txt
  7. npx tsreplay ./echarts path/to/replay.txt path/to/tsserver.js
replay.txt
{"rootDirPlaceholder":"@PROJECT_ROOT@","serverArgs":["--disableAutomaticTypingAcquisition"]}
{"seq":1,"type":"request","command":"configure","arguments":{"preferences":{"includePackageJsonAutoImports":"off"},"watchOptions":{"excludeDirectories":["**/node_modules"]}}}
{"seq":2,"type":"request","command":"updateOpen","arguments":{"changedFiles":[],"closedFiles":[],"openFiles":[{"file":"@PROJECT_ROOT@/dist/echarts.common.min.js","projectRootPath":"@PROJECT_ROOT@"}]}}
{"seq":3,"type":"request","command":"references","arguments":{"file":"@PROJECT_ROOT@/dist/echarts.common.min.js","line":45,"offset":362884}}
RangeError: Invalid string length
    at JSON.stringify (<anonymous>)
    at formatMessage (typescript/built/local/tsserver.js:174550:29)
    at IOSession.Session.writeMessage (typescript/built/local/tsserver.js:175529:31)
    at IOSession.Session.send (typescript/built/local/tsserver.js:175526:22)
    at IOSession.Session.doOutput (typescript/built/local/tsserver.js:175579:22)
    at IOSession.Session.onMessage (typescript/built/local/tsserver.js:177220:30)

One (of several?) problematic reference is at line 45, offsets 280-284 of echarts/dist/echarts.common.min.js.

A nice solution would truncate before and after a range containing the offset of interest. A minimal solution would truncate from the end, possibly cutting off the actual reference.

@amcasey
Copy link
Member Author

amcasey commented Aug 1, 2022

Presumably, there were too many references to fit in a response. It's not obvious what we want to do about this.

@amcasey
Copy link
Member Author

amcasey commented Aug 1, 2022

We appear to be looking for references to Object.create. There are only 4314, but I wonder if some are in minified files and the line text is super long. Really, we should probably truncate that.

Edit: yep, one lineText has length 567275.

@amcasey amcasey changed the title RangeError during references request Truncate lineText in references responses to avoid RangeError Aug 1, 2022
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 4, 2022
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Oct 10, 2022
@navya9singh
Copy link
Member

#51081

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants