mrjosh / helm-ls

⎈ Language server for Helm ⎈
MIT License
238 stars 15 forks source link

panic: runtime error: index out of range #81

Closed yvesjans closed 6 months ago

yvesjans commented 6 months ago

Recently I started experiencing helm-ls crashing when using specific helm charts using a range in the template. We do this for example to generate multiple deployments (e.g. spot vs ondemand nodes)

[ERROR][2024-05-19 14:13:55] .../vim/lsp/rpc.lua:770    "rpc"   "helm_ls"       "stderr"        "panic: runtime error: index out of range [0] with length 0\n\ngoroutine 28 [running]:\n"
[ERROR][2024-05-19 14:13:55] .../vim/lsp/rpc.lua:770    "rpc"   "helm_ls"       "stderr"        "github.com/mrjosh/helm-ls/internal/language_features.(*TemplateContextFeature).Hover(0x14000616040)\n\tgithub.com/mrjosh/helm-ls/internal/language_features/template_context.go:86 +0x568\ngithub.com/mrjosh/helm-ls/internal/handler.(*langHandler).Hover(0x140004ae0c0, {0x102546c70, 0x14000428000}, 0x14000558000)\n\tgithub.com/mrjosh/helm-ls/internal/handler/hover.go:31 +0x284\ngo.lsp.dev/protocol.serverDispatch({0x102546c70, 0x14000428000}, {0x102558e28, 0x140004ae0c0}, 0x14000550060, {0x102546df8, 0x140005c8180})\n\tgo.lsp.dev/protocol@v0.12.0/server.go:434 +0x1bb0\ngo.lsp.dev/protocol.NewServer.ServerHandler.func1({0x102546c70, 0x14000428000}, 0x14000550060, {0x102546df8, 0x140005c8180})\n\tgo.lsp.dev/protocol@v0.12.0/server.go:36 +0x6c\ngo.lsp.dev/protocol.Handlers.ReplyHandler.func1({0x102546c70, 0x14000428000}, 0x140005ba060, {0x102546df8?, 0x140005c8180?})\n\tgo.lsp.dev/jsonrpc2@v0.10.0/handler.go:35 +0xdc"
[ERROR][2024-05-19 14:13:55] .../vim/lsp/rpc.lua:770    "rpc"   "helm_ls"       "stderr"        "\ngo.lsp.dev/protocol.Handlers.AsyncHandler.func2.2()\n\tgo.lsp.dev/jsonrpc2@v0.10.0/handler.go:114 +0x78\ncreated by go.lsp.dev/protocol.Handlers.AsyncHandler.func2 in goroutine 8\n\tgo.lsp.dev/jsonrpc2@v0.10.0/handler.go:112 +0x194\n"

Chart to reproduce attached helm-lsp-repro.tar.gz

Open templates/deployment.yaml and hover doc on $config.hpa.minReplicas makes helm-ls panic

.local/share/nvim/mason/bin/helm_ls version
Helm-ls version: master
Git commit: aab553b
Build type: Release
Build time: 2024-05-09_02:37:42PM
Golang: go1.21.5
Compiled by: fv-az529-500

nvim --version
NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713773202
Run "nvim -V1 -v" for more info
qvalentin commented 6 months ago

Thanks for reporting. Using variable in the template context is currently not supported. E.g. something like this:

{{- $root := . -}}
{{- $root.Values.deployments }}

wont' give a result. But it should not crash the lsp anymore.

qvalentin commented 6 months ago

I opened https://github.com/mrjosh/helm-ls/issues/84 for the general support of this syntax.

yvesjans commented 6 months ago

Thanks for the quick fix! All working again :)