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

fix(ls): panic when failing to load root config. #1441

Merged
merged 1 commit into from
Feb 10, 2024
Merged

Conversation

i4ki
Copy link
Contributor

@i4ki i4ki commented Feb 10, 2024

What this PR does / why we need it:

When an error happens while looking for the root config, the language server panics with the stack trace below:

2024-02-10T14:38:52Z DBG handling request. action=server.Handler() method=textDocument/didOpen params={"textDocument":{"languageId":"terramate","text":"terramate {\n    config {\n        git {\n            default_branch = \"trunk\"\n        }\n    }\n}\n","uri":"file:///Users/tiagodemoura/src/vscode-terramate/testFixture/invalid/multiple-tm-config-git/tm2.tm","version":1}} workspace=/Users/tiagodemoura/src/vscode-terramate
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1012a3d04]

goroutine 8 [running]:
github.com/terramate-io/terramate/config.(*Root).Tree(...)
	/Users/tiagodemoura/src/terramate/config/config.go:125
github.com/terramate-io/terramate/ls.(*Server).checkFiles(0x140001102d0, {0x140002ce380, 0x2, 0x101287df4?}, {0x14000024697, 0x5a}, {0x1400001ab40, 0x5e})
	/Users/tiagodemoura/src/terramate/ls/ls.go:370 +0x64
github.com/terramate-io/terramate/ls.(*Server).checkAndReply(0x14000024690?, {0x101414268, 0x140001d1040}, 0x140002ce320, {0x14000024697, 0x5a}, {0x1400001ab40, 0x5e})
	/Users/tiagodemoura/src/terramate/ls/ls.go:324 +0x10c
github.com/terramate-io/terramate/ls.(*Server).handleDocumentOpen(0x73?, {0x101414268, 0x140001d1040}, 0x1400014cab8?, {0x1264f6e98, 0x140002c2e70}, {{0x101412b48, 0x14000027ff0}, 0xff, {0x0, ...}, ...})
	/Users/tiagodemoura/src/terramate/ls/ls.go:184 +0xf4
github.com/terramate-io/terramate/ls.(*Server).Handler(0x140001102d0, {0x101414268, 0x140001d1040}, 0x140002ce320, {0x1264f6e98?, 0x140002c2e70?})
	/Users/tiagodemoura/src/terramate/ls/ls.go:90 +0x418
go.lsp.dev/jsonrpc2.(*conn).run(0x140001d2ff0, {0x101414268, 0x140001d1040}, 0x140001e81f0)
	/Users/tiagodemoura/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/conn.go:206 +0x258
created by go.lsp.dev/jsonrpc2.(*conn).Go in goroutine 1
	/Users/tiagodemoura/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/conn.go:189 +0xa8
[Error - 14:38:52] Connection to server got closed. Server will not be restarted.

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

yes, fixes a LS bug.

Signed-off-by: Tiago Natel <t.nateldemoura@gmail.com>
@i4ki i4ki requested a review from a team as a code owner February 10, 2024 15:25
Copy link

netlify bot commented Feb 10, 2024

Deploy Preview for docs-terramate-io canceled.

Name Link
🔨 Latest commit b4d54d8
🔍 Latest deploy log https://app.netlify.com/sites/docs-terramate-io/deploys/65c79585493e3a0008c40439

Copy link

metric: time/op
CloudReadLines-4: old 883µs ± 4%: new 879µs ± 4%: delta: 0.00%
CloudReadLine-4: old 6.67ms ± 3%: new 6.56ms ± 2%: delta: -1.77%
ListFiles-4: old 49.8µs ± 2%: new 50.0µs ± 2%: delta: 0.00%
Generate-4: old 2.44s ± 3%: new 2.48s ± 2%: delta: 1.38%
GenerateRegex-4: old 1.73s ± 2%: new 1.74s ± 1%: delta: 0.78%
TokensForExpressionComplex-4: old 1.11ms ± 1%: new 1.12ms ± 0%: delta: 0.92%
TokensForExpressionPlainStringNoNewline-4: old 912ns ± 3%: new 933ns ± 1%: delta: 2.29%
TokensForExpressionStringWith100Newlines-4: old 33.2µs ± 2%: new 33.5µs ± 3%: delta: 0.00%
TokensForExpressionObjectWith100KeysWithNumberValues-4: old 1.24ms ± 3%: new 1.24ms ± 3%: delta: 0.00%
TokensForExpression-4: old 1.08ms ± 3%: new 1.09ms ± 3%: delta: 1.06%
PartialEvalComplex-4: old 417µs ± 4%: new 421µs ± 2%: delta: 0.82%
PartialEvalSmallString-4: old 3.49µs ± 2%: new 3.51µs ± 2%: delta: 0.00%
PartialEvalHugeString-4: old 1.82ms ± 3%: new 1.81ms ± 2%: delta: 0.00%
PartialEvalHugeInterpolatedString-4: old 4.62ms ± 1%: new 4.65ms ± 2%: delta: 0.00%
PartialEvalObject-4: old 21.1µs ± 2%: new 20.8µs ± 2%: delta: -1.62%
TmAllTrueLiteralList-4: old 5.42ms ± 3%: new 5.34ms ± 1%: delta: -1.46%
TmAllTrueFuncall-4: old 139µs ± 3%: new 138µs ± 2%: delta: -1.04%
TmAnyTrueLiteralList-4: old 126ms ± 3%: new 125ms ± 1%: delta: -1.42%
TmAnyTrueFuncall-4: old 139µs ± 2%: new 138µs ± 1%: delta: 0.00%
TmTernary-4: old 2.50µs ± 2%: new 2.50µs ± 2%: delta: 0.00%
TmTry-4: old 50.6µs ± 1%: new 50.6µs ± 2%: delta: 0.00%
metric: alloc/op
CloudReadLines-4: old 3.12MB ± 0%: new 3.12MB ± 0%: delta: 0.00%
CloudReadLine-4: old 3.37MB ± 0%: new 3.37MB ± 0%: delta: 0.00%
ListFiles-4: old 22.0kB ± 0%: new 22.0kB ± 0%: delta: 0.00%
Generate-4: old 2.31GB ± 0%: new 2.31GB ± 0%: delta: 0.00%
GenerateRegex-4: old 950MB ± 0%: new 949MB ± 0%: delta: 0.00%
TokensForExpressionComplex-4: old 412kB ± 0%: new 412kB ± 0%: delta: 0.00%
TokensForExpressionPlainStringNoNewline-4: old 592B ± 0%: new 592B ± 0%: delta: 0.00%
TokensForExpressionStringWith100Newlines-4: old 14.0kB ± 0%: new 14.0kB ± 0%: delta: 0.00%
TokensForExpressionObjectWith100KeysWithNumberValues-4: old 402kB ± 0%: new 402kB ± 0%: delta: 0.00%
TokensForExpression-4: old 412kB ± 0%: new 412kB ± 0%: delta: 0.00%
PartialEvalComplex-4: old 353kB ± 0%: new 353kB ± 0%: delta: 0.00%
PartialEvalSmallString-4: old 1.74kB ± 0%: new 1.74kB ± 0%: delta: 0.00%
PartialEvalHugeString-4: old 166kB ± 0%: new 166kB ± 0%: delta: 0.00%
PartialEvalHugeInterpolatedString-4: old 4.38MB ± 0%: new 4.38MB ± 0%: delta: 0.00%
PartialEvalObject-4: old 20.4kB ± 0%: new 20.4kB ± 0%: delta: 0.00%
TmAllTrueLiteralList-4: old 1.74MB ± 0%: new 1.74MB ± 0%: delta: 0.00%
TmAllTrueFuncall-4: old 45.5kB ± 0%: new 45.5kB ± 0%: delta: 0.00%
TmAnyTrueLiteralList-4: old 37.9MB ± 0%: new 37.9MB ± 0%: delta: 0.00%
TmAnyTrueFuncall-4: old 45.6kB ± 0%: new 45.6kB ± 0%: delta: 0.00%
TmTernary-4: old 1.11kB ± 0%: new 1.11kB ± 0%: delta: 0.00%
TmTry-4: old 11.1kB ± 0%: new 11.1kB ± 0%: delta: 0.00%
metric: allocs/op
CloudReadLines-4: old 5.54k ± 0%: new 5.54k ± 0%: delta: 0.00%
CloudReadLine-4: old 60.0k ± 0%: new 60.0k ± 0%: delta: 0.00%
ListFiles-4: old 321 ± 0%: new 321 ± 0%: delta: 0.00%
Generate-4: old 25.9M ± 0%: new 25.9M ± 0%: delta: 0.00%
GenerateRegex-4: old 18.3M ± 0%: new 18.3M ± 0%: delta: 0.00%
TokensForExpressionComplex-4: old 4.93k ± 0%: new 4.93k ± 0%: delta: 0.00%
TokensForExpressionPlainStringNoNewline-4: old 21.0 ± 0%: new 21.0 ± 0%: delta: 0.00%
TokensForExpressionStringWith100Newlines-4: old 328 ± 0%: new 328 ± 0%: delta: 0.00%
TokensForExpressionObjectWith100KeysWithNumberValues-4: old 3.29k ± 0%: new 3.29k ± 0%: delta: 0.00%
TokensForExpression-4: old 4.93k ± 0%: new 4.93k ± 0%: delta: 0.00%
PartialEvalComplex-4: old 2.83k ± 0%: new 2.83k ± 0%: delta: 0.00%
PartialEvalSmallString-4: old 23.0 ± 0%: new 23.0 ± 0%: delta: 0.00%
PartialEvalHugeString-4: old 35.0 ± 0%: new 35.0 ± 0%: delta: 0.00%
PartialEvalHugeInterpolatedString-4: old 23.1k ± 0%: new 23.1k ± 0%: delta: 0.00%
PartialEvalObject-4: old 125 ± 0%: new 125 ± 0%: delta: 0.00%
TmAllTrueLiteralList-4: old 13.6k ± 0%: new 13.6k ± 0%: delta: 0.00%
TmAllTrueFuncall-4: old 460 ± 0%: new 460 ± 0%: delta: 0.00%
TmAnyTrueLiteralList-4: old 252k ± 0%: new 252k ± 0%: delta: 0.00%
TmAnyTrueFuncall-4: old 462 ± 0%: new 462 ± 0%: delta: 0.00%
TmTernary-4: old 26.0 ± 0%: new 26.0 ± 0%: delta: 0.00%
TmTry-4: old 144 ± 0%: new 144 ± 0%: delta: 0.00%

@i4ki i4ki merged commit fd4bd4c into main Feb 10, 2024
13 checks passed
@i4ki i4ki deleted the i4k-fix-ls-experiments branch February 10, 2024 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants