Skip to content

Panic in incremental with tsbuildinfo with mismatched fileNames and fileInfos #1619

@benjaminjkraft

Description

@benjaminjkraft

Stack trace

panic: runtime error: index out of range [61666] with length 61666

goroutine 1 [running]:
github.com/microsoft/typescript-go/internal/incremental.(*toSnapshot).toFilePath(...)
        /Users/benkraft/src/typescript-go/internal/incremental/buildinfotosnapshot.go:61
github.com/microsoft/typescript-go/internal/incremental.(*toSnapshot).setFileInfoAndEmitSignatures(0x140001ac800)
        /Users/benkraft/src/typescript-go/internal/incremental/buildinfotosnapshot.go:104 +0x400
github.com/microsoft/typescript-go/internal/incremental.buildInfoToSnapshot(0x140001c8b40, {0x140011feff0?, 0x46?}, 0x140001c87e0, {0x1031730d8, 0x140001eda40})
        /Users/benkraft/src/typescript-go/internal/incremental/buildinfotosnapshot.go:34 +0x328
github.com/microsoft/typescript-go/internal/incremental.ReadBuildInfoProgram(0x140001c87e0, {0x10316db20, 0x1400021c2c0}, {0x1031730d8, 0x140001eda40})
        /Users/benkraft/src/typescript-go/internal/incremental/incremental.go:53 +0xd4
github.com/microsoft/typescript-go/internal/execute.performIncrementalCompilation({0x103174ed8, 0x14000182c00}, 0x140001c87e0, 0x140011f9140, {0x10316db00, 0x140000c78c0}, 0x5480e30b, {0x0, 0x0})
        /Users/benkraft/src/typescript-go/internal/execute/tsc.go:251 +0x1fc
github.com/microsoft/typescript-go/internal/execute.tscCompilation({0x103174ed8, 0x14000182c00}, 0x140001c8c60, {0x0, 0x0})
        /Users/benkraft/src/typescript-go/internal/execute/tsc.go:198 +0x87c
github.com/microsoft/typescript-go/internal/execute.CommandLine({0x103174ed8, 0x14000182c00}, {0x14000020060, 0x4, 0x4}, {0x0, 0x0})
        /Users/benkraft/src/typescript-go/internal/execute/tsc.go:67 +0x1b4
main.runMain()
        /Users/benkraft/src/typescript-go/cmd/tsgo/main.go:23 +0x120
main.main()
        /Users/benkraft/src/typescript-go/cmd/tsgo/main.go:10 +0x1c

Steps to reproduce

I haven't been able to repro this in isolation -- one of our internal users ran into it and I can repro it by doing an incremental build from their tsbuildinfo file. I don't think I can share the full file but here's a relevant fact about it:

$ jq '.fileInfos|length' path/to/tsconfig.tsbuildinfo
61667
$ jq '.fileNames|length' path/to/tsconfig.tsbuildinfo
61666

Perhaps as a start the tsbuildinfo loader should validate this? It's a bit harder for me to figure out how the tsbuildinfo got that way, but I'm gonna try. (My guess is maybe some kind of casing-conflict or other condition that causes two file-infos for one file name? The code doesn't really look like it ensures they are 1:1, but then it assumes they are, I think.) Let me know if anyone has ideas for what to look at, or which other facts about the tsbuildinfo might be of interest.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions