typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

Panic on textDocument/definition

Open lukpsaxo opened this issue 3 months ago • 5 comments

Stack trace

panic handling request textDocument/definition bad line number. Line: 65, lineMap length: 33 goroutine 74379 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:26 +0x5e
github.com/microsoft/typescript-go/internal/lsp.(*Server).recover(0xc0000f4dc0, 0xc05d9571d0)
	github.com/microsoft/typescript-go/internal/lsp/server.go:532 +0x58
panic({0x7ff76dc5a4c0?, 0xc02a3d9970?})
	runtime/panic.go:783 +0x132
github.com/microsoft/typescript-go/internal/ls.(*Converters).LineAndCharacterToPosition(0xc025592360, {0x7ff76dfe4430, 0xc03fbe7608}, {0x0?, 0x0?})
	github.com/microsoft/typescript-go/internal/ls/converters.go:143 +0x2d9
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ProvideDefinition(0xc010739488, {0x7ff76dfe59d0, 0xc05eecf360}, {0xc02e3db420?, 0x7ff76d5a94f0?}, {0x0?, 0x0?})
	github.com/microsoft/typescript-go/internal/ls/definition.go:17 +0xac
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleDefinition(0xc0003501c0?, {0x7ff76dfe59d0?, 0xc05eecf360?}, 0xc02e3db420?, 0x65?)
	github.com/microsoft/typescript-go/internal/lsp/server.go:735 +0x35
github.com/microsoft/typescript-go/internal/lsp.init.func1.registerLanguageServiceDocumentRequestHandler[...].13({0x7ff76dfe59d0, 0xc05eecf360}, 0xc05d9571d0)
	github.com/microsoft/typescript-go/internal/lsp/server.go:518 +0x13f
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleRequestOrNotification(0xc0000f4dc0, {0x7ff76dfe59d0, 0xc05eecf360}, 0xc05d9571d0)
	github.com/microsoft/typescript-go/internal/lsp/server.go:424 +0x10d
github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1()
	github.com/microsoft/typescript-go/internal/lsp/server.go:329 +0x3a
created by github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop in goroutine 10
	github.com/microsoft/typescript-go/internal/lsp/server.go:349 +0x8aa

[Error - 9:42:06 AM] Request textDocument/definition failed.
  Message: InternalError: panic handling request textDocument/definition: bad line number. Line: 65, lineMap length: 33
  Code: -32603 

Steps to reproduce

I couldn't easily reproduce again. I was commenting out some code and then it appeared to error when the editor lost focus. I tried re-doing edits and it didn't occur.

The file I am in has 44 lines so not sure where bad line number 65 or line map length 33 came from.

Checking the LSP logs:

[Trace - 9:42:06 AM] Sending request 'textDocument/definition - (54)'.
Params: {
    "textDocument": {
        "uri": "file:///c%3A/Projects/a/b/c.play.ts"
    },
    "position": {
        "line": 65,
        "character": 24
    }
}


[Trace - 9:42:06 AM] Received response 'textDocument/definition - (54)' in 1ms. Request failed: InternalError: panic handling request textDocument/definition: bad line number. Line: 65, lineMap length: 33 (-32603).

so It seems it is a vscode issue - asking for a wrong line number?!

Feel free to close - I guess when this is production it will ignore errors like this instead of popping up.

lukpsaxo avatar Sep 03 '25 07:09 lukpsaxo

Do other files in the same folder have the same name but different extensions?

iisaduan avatar Sep 03 '25 20:09 iisaduan

No, the filename was unique. I had moved it and then started editing.

lukpsaxo avatar Sep 04 '25 07:09 lukpsaxo

@iisaduan I get this error every couple of minutes (in a very large monorepo).

Is there a way to silence the popup?

[Error - 10:30:25 AM] Request textDocument/definition failed.
  Message: InternalError: panic handling request textDocument/definition: runtime error: invalid memory address or nil pointer dereference
  Code: -32603 
panic handling request textDocument/definition runtime error: invalid memory address or nil pointer dereference goroutine 99550 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:26 +0x64
github.com/microsoft/typescript-go/internal/lsp.(*Server).recover(0x1400017cdc0, 0x1404924ad50)
	github.com/microsoft/typescript-go/internal/lsp/server.go:542 +0x44
panic({0x104d7ce40?, 0x105523e00?})
	runtime/panic.go:783 +0x120
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getMappedLocation(0x140493d7a10, {0x140058ad180, 0x65}, {0x4a8d8b0?, 0x1?})
	github.com/microsoft/typescript-go/internal/ls/source_map.go:21 +0x4c
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).createLocationsFromDeclarations(0x140493d7a10, {0x1400ca67360, 0x1, 0x140044a8008?})
	github.com/microsoft/typescript-go/internal/ls/definition.go:108 +0x114
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ProvideDefinition(0x140493d7a10, {0x104f663b0, 0x14021f1dd60}, {0x1402edb1c80?, 0x14008668a00?}, {0x280?, 0x0?})
	github.com/microsoft/typescript-go/internal/ls/definition.go:57 +0x314
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleDefinition(0x1400027a000?, {0x104f663b0?, 0x14021f1dd60?}, 0x1402edb1c80?, 0x60?)
	github.com/microsoft/typescript-go/internal/lsp/server.go:766 +0x38
github.com/microsoft/typescript-go/internal/lsp.init.func1.registerLanguageServiceDocumentRequestHandler[...].13({0x104f663b0, 0x14021f1dd60}, 0x1404924ad50)
	github.com/microsoft/typescript-go/internal/lsp/server.go:528 +0xf0
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleRequestOrNotification(0x1400017cdc0, {0x104f663b0, 0x14021f1dd60}, 0x1404924ad50)
	github.com/microsoft/typescript-go/internal/lsp/server.go:425 +0xf4
github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1()
	github.com/microsoft/typescript-go/internal/lsp/server.go:330 +0x34
created by github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop in goroutine 6
	github.com/microsoft/typescript-go/internal/lsp/server.go:350 +0x6f8

richburdon avatar Oct 22 '25 14:10 richburdon

@richburdon That's #1867. I don't think this should be too hard to fix quick.

jakebailey avatar Oct 22 '25 16:10 jakebailey

panic handling request textDocument/definition bad line number. Line: 24, lineMap length: 23 goroutine 43742 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:26 +0x5e
github.com/microsoft/typescript-go/internal/lsp.(*Server).recover(0xc00017cdc0, 0xc02ea55800)
	github.com/microsoft/typescript-go/internal/lsp/server.go:567 +0x58
panic({0xb147a0?, 0xc017495f00?})
	runtime/panic.go:783 +0x132
github.com/microsoft/typescript-go/internal/ls.(*Converters).LineAndCharacterToPosition(0xc01695b8a8, {0xea6f90, 0xc01cfde908}, {0xf21dda8?, 0xc0?})
	github.com/microsoft/typescript-go/internal/ls/converters.go:143 +0x2d9
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ProvideDefinition(0xc02d676900, {0xea88c0, 0xc01ba8a960}, {0xc01c5f6600?, 0x10000c02698b620?}, {0x0?, 0x0?})
	github.com/microsoft/typescript-go/internal/ls/definition.go:17 +0xaf
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleDefinition(0xc00031ca20?, {0xea88c0?, 0xc01ba8a960?}, 0xc01c5f6600?, 0x53?)
	github.com/microsoft/typescript-go/internal/lsp/server.go:815 +0x35
github.com/microsoft/typescript-go/internal/lsp.init.func1.registerLanguageServiceDocumentRequestHandler[...].14({0xea88c0, 0xc01ba8a960}, 0xc02ea55800)
	github.com/microsoft/typescript-go/internal/lsp/server.go:553 +0x13f
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleRequestOrNotification(0xc00017cdc0, {0xea88c0, 0xc01ba8a960}, 0xc02ea55800)
	github.com/microsoft/typescript-go/internal/lsp/server.go:449 +0x10d
github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1()
	github.com/microsoft/typescript-go/internal/lsp/server.go:354 +0x3a
created by github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop in goroutine 34
	github.com/microsoft/typescript-go/internal/lsp/server.go:374 +0x9ad

jakebailey avatar Oct 25 '25 20:10 jakebailey